Laravel软删除恢复()错误
问题描述:
下面的软删除代码工作正常,我:Laravel软删除恢复()错误
$post = Post::find($post_id);
$post->delete();
的deleted_at场被更新。但是,这给了我一个错误:
$post = Post::find($post_id);
$post->restore();
这里的错误:
exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Call to a member function restore() on a non-object'
我难倒。谷歌迄今为止没有帮助。
答
错误说$post
是一个非对象,Laravel不无withTrashed()
Post::withTrashed()->find($post_id)->restore();
When querying a model that uses soft deletes, the "deleted" models will not be included...
就像一个魅力返回丢弃记录。谢谢。 – moreirapontocom 2017-09-18 14:10:41