Laravel Auth manually login by id

Anuj kumar picture Anuj kumar · Jan 29, 2019 · Viewed 9.7k times · Source

I am new to laravel and I am working with a functionality where we insert data in user table with

DB::insert();

After that i get last id with

$user_id = DB::getPdo()->lastInsertId();

Now I want user to login after register and I am trying to

Auth::loginUsingId($user_id);

But its returning me false. I also tried

$user = User::find($user_id);
Auth::login($user);

Its also return null $user.

Please help...

Answer

atf.sgf picture atf.sgf · Jan 29, 2019

Login User:

Auth::login($user);

check current user is login or not:

Auth::check();