雄辩地说明如何更新Deleted_at列

时间:2020-06-01 08:17:57

标签: laravel eloquent

我正在尝试软删除记录,并且工作正常,但是我的表deleted_at显示为空,而updated_at也没有记录最新日期。 enter image description here

代码

public function destroy($id)
    {
        $record = Sale::findOrFail($id);

        if ($record->delete()) {
            return response()->json([
                'id' => $id,
                'success' => true,
            ]);
        } else {
            abort(404,'Sale not found.');
        }
    }

型号

我的模型已经实现

use SoftDeletes;
protected $dates = ['deleted_at'];

迁移

Schema::create('sales', function($table)
        {
            $table->increments('id')->unsigned();
            $table->string('ref_num', 50);
            $table->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP'));
            $table->timestamp('updated_at')->default(DB::raw('CURRENT_TIMESTAMP'))->nullable();
            $table->softDeletes();
        });

如何用当前时间更新updated_atdeleted_at列?

0 个答案:

没有答案