2014-08-29 11 views
9

Die folgenden Soft löschen Code funktioniert gut für mich:Laravel Weiche Löschen wiederherstellen() Fehler

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

Das deleted_at Feld aktualisiert wird. Aber das gibt mir eine Fehlermeldung:

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

Hier ist der Fehler:

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

ich ratlos bin. Google ist bisher keine Hilfe.

Antwort

20

Fehler sagt $post ein Nicht-Objekt ist, Laravel ohne trashed Datensätze nicht zurück 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

Arbeiten wie ein Charme. Vielen Dank. – moreirapontocom