Laravel v5.2. * (V5.2.29) Auth :: guard ('api') & # 8594; attempt ($ user) fatal error

Has anyone encountered this problem

dd($this->user->check()); return false 

but

 Auth::guard('user')->attempt(App\User::find(1)) 

return error

Call the undefined method Illuminate \ Auth \ TokenGuard :: try ()

Help solve this problem.

+5
source share
2 answers

I solved this problem

In config/auth.php :

 'user' => [ 'driver' => 'token', 'provider' => 'userProvider', ], 

We need to change to:

 'user' => [ 'driver' => 'session', 'provider' => 'userProvider', ], 

Since Auth::guard data is stored in the session

And further work on the well-known scheme

 Auth::login() = Auth::guard('user')->login() Auth::attempt() = Auth::guard('user')->attempt() Auth::user() = Auth::guard('user')->user() ... 
+7
source

You must pass an array of credits to the attempt function, not the user object.

For instance:

 Auth::guard('user')->attempt([ 'email' => ' some@email.com ', 'password' => '1234' ]); 

And if you use Laravel and you need to authenticate the user, you can call this:

 auth()->attempt([ 'email' => ' some@email.com ', 'password' => '1234' ]); 
+1
source

Source: https://habr.com/ru/post/1246763/


All Articles