Reputation: 177
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'
Upvotes: 3
Views: 1865
Reputation: 661
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);
Upvotes: 5