laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.55k stars 11.03k forks source link

Call to undefined method `App\Models\User::history()` #38895

Closed mahmoudmohamedramadan closed 3 years ago

mahmoudmohamedramadan commented 3 years ago

I was deal WITH softDeletes trait, and when I use the history method as exists in the docs the Call to undefined method App\Models\User::history() issue is triggered, here is my code

public function restoreUser(Request $request)
{
     $user_id = $request->route()->parameter('user');
     $user = User::onlyTrashed()->get()->find($user_id);

     if ($user->trashed()) {
        $user->history()->restore();
     }

     return redirect()->route('users.trashed');
}
Krisell commented 3 years ago

->history() is just an example relationship for the Flights model in the docs, it's not a framework method.

mahmoudmohamedramadan commented 3 years ago

@Krisell Thanks