Login Authentication

Laravel provides Auth class for authentication but before we use it first we have to create a login form.

We will create a file login.blade.php in user view directory.

login view file


Here is the code to create the login form.

Here we’ve set the action to user/loginUser. So now we will create a route to this location.



As I said in starting of this article, Laravel uses Auth class for authentication purpose.

Here in our route we used if(Auth::attempt($credentials)).

We have simply passed the login credentials array to the Auth class and it returns true or false.

If it returns true then login is success else login fails.

By default Laravel uses User model and users tabel for Auth class.

If you want to change the database table or model then you can do the settings in auth.php file in app/config/auth.php.

auth.php file location
auth.php file location


So you see how simple is your login work now in Laravel.

If you want to redirect your user to a page then insterad of return “true”; return Redirect::to(‘home’);


So you can go to http://localhost:8000/user/login and try it out.

We will do the form validations also but later.

Now in next article we will see how to use controllers in Laravel.

Share this article: