Laravel Record Update-更新记录时删除记录

时间:2019-08-19 15:35:48

标签: laravel eloquent model sql-update

我有服务的基本CRUD。我已经在模型中添加了SoftDeletes

.test {
  width: 25%;
  height: 35vh;
  background-image: url("data:image/svg+xml;charset=utf-8;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHByZXNlcnZlQXNwZWN0UmF0aW89Im5vbmUiIHZpZXdCb3g9IjAgMCA2NCA2NCI+PHBvbHlnb24gcG9pbnRzPSIwLDAgNjIuNTg1NzgsMCAwLDYyLjU4NTc4IiBmaWxsPSIjNDRGNjkwIi8+PHBvbHlnb24gcG9pbnRzPSI2NCwxLjQxNDIxIDY0LDY0IDEuNDE0MjEsNjQiIGZpbGw9IiM0N0NGRjMiLz48L3N2Zz4=");
  background-size: 100% 100%;
  resize: both;
}
/*
The sample SVG is now:
<svg xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="none" viewBox="0 0 64 64">
<polygon points="0,0 62.58578,0 0,62.58578" fill="#44F690"/>
<polygon points="64,1.41421 64,64 1.41421,64" fill="#47CFF3"/>
</svg>
*/

更新记录时,我使用的是Laravel Eloquent,这是代码:

<div class="test"></div>

web.php 中的路由为:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Service extends Model
{
    use SoftDeletes;

    protected $table = 'services';
    protected $fillable = [
          'name','description',
    ];
}

我不知道为什么会发生这种情况,但是每次我尝试更新记录时, public function update(Request $request) { $this->validate($request, [ 'name' => 'required', ]); $service = Service::find($request->id); $service->name = $request->name; $service->description = $request->description; $service->save(); } 列也会被更新(其中填充了时间戳)。我想要的是,记录将被更新而不被删除。

PS

我也在具有Route::post('service/update', 'ServiceController@update') ->name('updateService'); 的其他模型中进行了尝试,并且该问题也出现了,记录被更新然后被删除。

0 个答案:

没有答案