Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel authentication confusing

I'm beginner at Laravel.

I wanted to use:

Auth::login(users::find(1))

Result: Type error:

Argument 1 passed to Illuminate\Auth\SessionGuard::login() must be an instance of Illuminate\Contracts\Auth\Authenticatable, instance of App\users given

I changed the model to extend Authenticatable instead of Model. Also I changed the Auth statement to:

Auth::login(users::where('id', 1))

Result: Type error:

Argument 1 passed to Illuminate\Auth\SessionGuard::login() must implement interface Illuminate\Contracts\Auth\Authenticatable, instance of Illuminate\Database\Eloquent\Builder given

I wonder if you would help me, 'Appreciation'

like image 448
Arya Basiri Avatar asked May 11 '26 16:05

Arya Basiri


1 Answers

You, should implement Illuminate\Contracts\Auth\Authenticatable in users Model class to pass through Auth::login

Authenticate A User Instance

If you need to log an existing user instance into your application, you may call the login method with the user instance. The given object must be an implementation of the Illuminate\Contracts\Auth\Authenticatable contract. Of course, the App\User model included with Laravel already implements this interface:

Auth::login($user);

https://laravel.com/docs/5.1/authentication

Or you can simply do this:

Auth::loginUsingId(1);
like image 84
Phoebus Avatar answered May 14 '26 21:05

Phoebus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!