2014-08-29 24 views
9

Il seguente codice di eliminazione morbida funziona bene per me:laravel soft Delete ripristinare() Errore

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

Il campo deleted_at viene aggiornato. Ma questo mi dà un errore:

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

Ecco l'errore:

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

stumped. Google non è di aiuto finora.

risposta

20

errore dice $post è un non-oggetto, laravel non restituisce record cestinati senza 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

funziona come un fascino. Grazie. – moreirapontocom