只需要修改/vendor/laravel/framework/src/Illuminate/Databases/Eloquent/SoftDeletes.php
里runSoftDelete
方法,如下列代码所示
/**
* for 'data_status' changes to
*/
protected $data_status = true;
/**
* Perform the actual delete query on this model instance.
*
* @return void
*/
protected function runSoftDelete()
{
$query = $this->setKeysForSaveQuery($this->newModelQuery());
$time = $this->freshTimestamp();
$columns = [$this->getDeletedAtColumn() => $this->fromDateTime($time)];
$this->{$this->getDeletedAtColumn()} = $time;
if ($this->timestamps && ! is_null($this->getUpdatedAtColumn())) {
$this->{$this->getUpdatedAtColumn()} = $time;
$columns[$this->getUpdatedAtColumn()] = $this->fromDateTime($time);
}
$columns = $columns + (array)($this->data_status?['data_status' => '0']:[]);
$query->update($columns);
$this->syncOriginalAttributes(array_keys($columns));
}
属性$data_status
用来开启或关闭修改,在方法runSoftDelete
中的变量$columns
就是laravel
软删除规定的字段修改,前提是当前数据表中必须要有这些字段;这里我的数据库软删除要修改数据库中data_status
字段,所以我在变量$columns
中拼接了['data_status' => '0']
数组,如果想修改其它字段,可以选择在变量$columns
中拼接,这样当你执行了软删除,这个方法就会被触发,调用update
方法将变量$columns
中的数据更新到数据库中