Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel v5.2.* (v5.2.29) Auth::guard('api')->attempt($user) fatal error

Tags:

php

laravel

Has anyone encountered this problem

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

but

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

return the error

Call to undefined method Illuminate\Auth\TokenGuard::attempt()

Please help to resolve this problem.

like image 850
Vanya Avchyan Avatar asked Apr 09 '16 09:04

Vanya Avchyan


1 Answers

I solved this problem

In config/auth.php configuration:

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

We need to change to:

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

Because 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()
...
like image 82
Vanya Avchyan Avatar answered Sep 28 '22 02:09

Vanya Avchyan