Laravel-销毁然后更新Deleted_by

时间:2020-03-30 03:18:49

标签: laravel

使用destroy后,我需要更新deleted_by字段时出现错误。我听说过可修订的内容,但我正在尝试使我的应用程序尽可能简单。甚至有可能在destroy内抛出另一个函数吗?

public function destroy($id, Department $department)
  {
        if(Department::destroy($id)) {
            $department->update([
                'deleted_by' => Auth::user()->id,
            ]);
        }
  }

错误: enter image description here

2 个答案:

答案 0 :(得分:3)

您可以使用路由模型绑定并执行以下操作:

public function destroy(Department $department)
{
    if($department->delete()) {
        $department->update([
            'deleted_by' => Auth::user()->id,
        ]);
    }
}

答案 1 :(得分:1)

您传递了错误的类型提示。

public function destroy(Department $department)
  {
        if($department->delete()) {
            $department->update([
                'deleted_by' => Auth::user()->id,
            ]);
        }
  }