I use manual login function in Laravel 5.5. Stuck in login. and check all(5 relevant ) Stack links and didn't find any clue on it.
Achievement is once user get registered, automatically sign in that user.
Error is
"Type error: Argument 1 passed to Illuminate\Auth\SessionGuard::login() must implement interface Illuminate\Contracts\Auth\Authenticatable, string given, called in Server/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php on line 294 ◀"
if ($validator->fails()) {
// $messages = $validator->messages();
return Redirect::to('register')
->withErrors($validator)
->withInput();
} else {
$email = Input::get('email');
$user = new user;
$user->name = Input::get('name');
$user->email = Input::get('email');
$user->password = Hash::make(Input::get('password'));
$user->save();
// $userMail = $user->find($email);
$userMail = User::where('email','=',$email)->first();
Auth::login($userMail->email, TRUE);
am i doing anything wrong. Please guide me.
Login function needs user of type Authenticatable
and you just given email
which is string thats why you get this error, Either use Auth::loginUsingId($id);
$user = User::where('email','=',$email)->first();
Auth::loginUsingId($user->id, TRUE);
Or just
Auth::login($user);
Instead of this
Auth::login($userMail->email, TRUE);
Use this
Auth::login($user->id, TRUE);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With