Minggu, 08 Juni 2014

Users Logging in into The Application Automatically

In some case, you don't want the user to type something to login.

In my case, I send an email to the user. The user clicked a link in their email and the user automatically logged in into the application.

I am sure you have a lot of reason for logging in the user without typing anything.

In Laravel documentation, they named it Manually Logging In Users. Well, I named it Automatically Logging In Users. Hehe... You choose whatever name is suitable for you.

This is the snippet;

//find the user id
$user = User::find(1);

//You can logging in the user 

Or the other way, you can logging in your user by a key that your have made in your database.

//Find the user base on a key
$user = DB::table('users')->where('the_key','=',$key)->first();
//automatically logging in