如何从Laravel中的表更新软删除的值

时间:2018-12-26 08:38:44

标签: laravel-5 soft-delete

因为我已经完成了此链接中提到的步骤。Laravel, Can't update a soft-deleted value .. 请帮助

1 个答案:

答案 0 :(得分:1)

在获取要编辑的数据时尝试使用withTashed()。

// suppose user with id 2 is soft deleted.
eg: User::find(2) // this will return null and you won't be able to update the user

要获取软删除的用户,应使用withTrashed()

eg: User::withTrashed()->find(2)->update(['deleted_at' => null);
Or User::withTrashed()->find(2)->restore();

ref:https://laravel.com/docs/5.7#soft-deleting