How to Manually Logging In A User in Laravel

By | July 8, 2021

If you want to log an existing user into your laravel application, There are various methods available we will discuss them one by one. To login the user manually in Laravel you need to follow the simple steps below for login.

Step 1. Fetch the user from the DB which you want to logging In in the Laravel.

$user = User::find(1); //You can add as per your condition (with email,password etc.)
Auth::login($user);

It will allow the user to logging in the Laravel application.

To manually login the user in Laravel has second optional argument, which is used for remember me. If you pass the second argument as true. If this argument passed as true then user will be logged in for indefinite time.

Auth::login($user, true);

https://laravel.com/docs/8.x/authentication#authenticate-a-user-instance

Leave a Reply