2014-08-29 25 views
9

Mã delete mềm sau hoạt động tốt đối với tôi:Laravel mềm Xóa khôi phục() Lỗi

$post = Post::find($post_id); 
$post->delete(); 

Trường deleted_at được cập nhật. Nhưng điều này mang lại cho tôi một lỗi:

$post = Post::find($post_id); 
$post->restore(); 

Dưới đây là các lỗi:

exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Call to a member function restore() on a non-object' 

tôi stumped. Google không giúp được gì cho đến nay.

Trả lời

20

Lỗi nói $post là một tổ chức phi vật thể, Laravel không trả lại hồ sơ cho vào thùng rác mà không 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

trình như một say mê. Cảm ơn bạn. – moreirapontocom

Các vấn đề liên quan