使用destroy
后,我需要更新deleted_by
字段时出现错误。我听说过可修订的内容,但我正在尝试使我的应用程序尽可能简单。甚至有可能在destroy
内抛出另一个函数吗?
public function destroy($id, Department $department)
{
if(Department::destroy($id)) {
$department->update([
'deleted_by' => Auth::user()->id,
]);
}
}
答案 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,
]);
}
}