S
S
SpinPr2018-05-28 11:36:07
Laravel
SpinPr, 2018-05-28 11:36:07

How to fix an authentication error?

One line of code from the documentation:
\Auth::login(1,true);
Throws an error:

FatalThrowableError in SessionGuard.php line 439:
Type error: Argument 1 passed to Illuminate\Auth\SessionGuard::login() must implement interface Illuminate\Contracts\Auth\Authenticatable, integer given

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kairat Ubukulov, 2018-05-28
@SpinPr

You are trying to login with ID.
Accordingly, there is a method for it:
Auth::loginUsingId(1);
Authenticate A User By ID
To log a user into the application by their ID, you may use the loginUsingId method. This method accepts the primary key of the user you wish to authenticate:
Auth::loginUsingId(1);
// Login and "remember" the given user...
Auth::loginUsingId(1, true);
https://laravel.com/docs/5.6/authentication

S
SpinPr, 2018-05-28
@SpinPr

$user = User::where('id',1)->first();
\Auth::login($user,true);
dd(\Auth::id());
Everything works, but the authorization is not saved ...
Do I need to force saving somewhere else?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question