2014-08-29 68 views
9

下面的软删除代码工作正常,我: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' 

我难倒。谷歌迄今为止没有帮助。

回答

20

错误说$post是一个非对象,Laravel不无withTrashed()

Post::withTrashed()->find($post_id)->restore(); 

Laravel Docs - Soft Deleting

When querying a model that uses soft deletes, the "deleted" models will not be included...

+0

就像一个魅力返回丢弃记录。谢谢。 – moreirapontocom 2017-09-18 14:10:41