Laravel restore() fails on a soft deleted model
Fix it fast
Most common cause, 1 of 3find() returns null because soft deleted rows are excluded
Load the row through withTrashed() or onlyTrashed() before calling restore(), and use findOrFail so a wrong id gives a clean 404 instead of a null error.
$post = Post::onlyTrashed()->findOrFail($id);
$post->restore();
// many at once (no model events are dispatched)
Post::withTrashed()->where('user_id', $userId)->restore();Short answer
"Call to a member function restore() on null" in Laravel 13 means the lookup skipped the row: soft deleted models are excluded from every normal query, find() included. Load it with withTrashed() or onlyTrashed() first. "Call to undefined method ...::restore()" means the model lacks the SoftDeletes trait, and a 404 on a restore route needs withTrashed() on the route.
Which cause do you have?
Check in Tinker whether the model uses the trait and whether the row is only reachable with withTrashed(). The two answers point to cause 1 or cause 2; a 404 from a route that works for live rows is cause 3.
php artisan tinker --execute="dump(in_array(Illuminate\Database\Eloquent\SoftDeletes::class, class_uses_recursive(App\Models\Post::class)), App\Models\Post::find(5), App\Models\Post::withTrashed()->find(5)?->deleted_at)"Then find the line you see in this list and open its fix:
- 1find() returns null because soft deleted rows are excluded
Post::find($id) is null in Tinker, while Post::withTrashed()->find($id) returns the model with a deleted_at date - 2The model does not use the SoftDeletes trait
Call to undefined method App\Models\Post::restore(), or the same for Illuminate\Database\Eloquent\Builder when restore() is called on a query - 3Route model binding hides the trashed model, so the restore route answers 404
The restore controller is never reached; the same route pattern works for posts that are not deleted
What does the error look like?
Call to a member function restore() on nullCall to undefined method App\Models\Post::restore()Call to undefined method Illuminate\Database\Eloquent\Builder::restore()404 Not Found on a route such as /posts/{post}/restore
Cause 1 of 3
find() returns null because soft deleted rows are excluded
You seePost::find($id) is null in Tinker, while Post::withTrashed()->find($id) returns the model with a deleted_at date
Check
Call to a member function restore() on null means the model was never loaded: once a model uses SoftDeletes, Laravel leaves rows with a deleted_at value out of all query results, so find(), first() and where() return nothing for them.
php artisan tinker --execute="dump(App\Models\Post::onlyTrashed()->pluck('id'))"Fix
Load the row through withTrashed() or onlyTrashed() before calling restore(), and use findOrFail so a wrong id gives a clean 404 instead of a null error. To restore many rows, call restore() on the query; that mass form fires no model events.
$post = Post::onlyTrashed()->findOrFail($id);
$post->restore();
// many at once (no model events are dispatched)
Post::withTrashed()->where('user_id', $userId)->restore();Verify
The row's deleted_at is null again and the model shows up in a plain find().
php artisan tinker --execute="dump(App\Models\Post::find(5)?->deleted_at)"Confirmed by laravel.com
Cause 2 of 3
The model does not use the SoftDeletes trait
You seeCall to undefined method App\Models\Post::restore(), or the same for Illuminate\Database\Eloquent\Builder when restore() is called on a query
Check
Call to undefined method ...::restore() means Eloquent has no restore method for this model, because restore(), withTrashed() and onlyTrashed() come from the Illuminate\Database\Eloquent\SoftDeletes trait. Without it, delete() also removes the row for good.
grep -n "SoftDeletes" app/Models/Post.phpFix
Add the trait to the model and a deleted_at column to the table with the schema builder's softDeletes() helper.
// app/Models/Post.php
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Post extends Model
{
use SoftDeletes;
}
// migration
Schema::table('posts', function (Blueprint $table) {
$table->softDeletes();
});Verify
Run the migration, delete a post, and restore it; the row stays in the table in between.
php artisan migrateConfirmed by laravel.com
Cause 3 of 3
Route model binding hides the trashed model, so the restore route answers 404
You seeThe restore controller is never reached; the same route pattern works for posts that are not deleted
Check
A 404 on a restore route with implicit model binding means the binding did not find the trashed model: by default implicit binding does not retrieve soft deleted models.
php artisan route:list --path=restoreFix
Chain withTrashed() onto the route definition, then restore inside the controller.
Route::post('/posts/{post}/restore', function (Post $post) {
$post->restore();
return back();
})->withTrashed();Verify
Post to the route for a deleted post: it redirects back and the post is live again.
php artisan route:list --path=restoreConfirmed by laravel.com
How do I stop it coming back?
- Write restore and force-delete actions against onlyTrashed() queries, never against plain find().
- Add withTrashed() to every route that must reach deleted records, and cover it with a feature test that restores one.
- Add the SoftDeletes trait and the softDeletes() column in the same commit, so the model and the table never disagree.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: Spotless Laundry, EZ Estimater.