This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

CloudwaysCDN — a powerful solution that offers superior performance and satisfied global audience for your business. Read More

How to Setup Laravel Login Authentication in Simple and Easy Steps

Updated on  February 24, 2018

4 Min Read
Reading Time: 4 minutes

In this tutorial, I will discuss how to implement Laravel login authentication. An important feature of this Laravel 5.5 authentication example implementation is that it filters out and generates an error whenever the authentication credentials (for example, email and/or password) are incorrectly entered by the user(s).

Laravel-Login-Authentication-Banner

Prerequisites for Laravel 5.5 custom authentication:

  1. Cloudways Server. Get your server on Cloudways if you do not have one.
  2. Launch a Laravel 5.5 app.

Step 1: Setup the Database

  • Go to your Laravel application on the Cloudways server.
  • Click on Launch Database.
  • Click on Create Table. Name the new table users and select innoDB and ascii_general
  • Add the following columns in the table:
    • id (int)   (Check AutoIncrement A.I.)
    • name (text)
    • username (text)
    • email (text)
    • password (text)
    • remember_token (text)
    • timestamp (time)
  • Click Save
  • Now Click New Item and then add the following user:
    • Name: Harry Potter
    • Username: BoyWhoLived
    • Email: harrypotter@hogwarts.edu.uk
    • Password: caputdraconis
  • Click Save

Step 2: Setup the Routes

Here lies all the endpoints.

Let’s make three endpoints:

  1. Post Call to submit the form
  2. Get Call to show the login form
  3. To LogOut.

Step 3: Make the Controllers

I will extend MainController from the Base Controller and make three functions to show login, check the login and for logging out.

Following is the code for MainController:

Step 4: Setup the View

Now let’s make the view, which will contain the HTML code of the app.

The .blade.php extension lets Laravel know that I am using its Blade Templating system.

 

Here is the HTML code for this file.

Now let’s check how the app looks!

Laravel Login

This is a simple example of how you could implement login authentication in a Laravel app.

Another Laravel 5.5 login and registration Setup

Here is a GIF that explains the entire process:

Database Migration

In a Laravel powered app, database configuration is handled by two files: env and config/database.php. In my case, I created a database with the name loginuser. The Cloudways Database Manager makes the entire process very easy.

Next, run the following command in the terminal to create tables in the database:

Login to SSH terminal by using Master Credentials and go to the application folder by using the command

 

Now, when you check the database, you will see that the tables have been created successfully.

Laravel 5.5 authentication

This command should be used in fresh applications and will install a layout view, registration and login views, as well as routes for all authentication endpoints.

Register

Login

Use Username for Authentication

Laravel uses the provided email address as the default authentication field. However, users prefer to use their username instead of emails. To change the default behavior, here is how to define a username in the

Login Controller

If you have a question about this Laravel 5.5 authorization example or wish to add to the conversation about Laravel 5.5 login example, please leave a comment below.

 

Share your opinion in the comment section. COMMENT NOW

Create Laravel apps without the worry of server management.

Deploy your app on optimized PHP hosting servers for Laravel.

About The Author

Noor Ali

Noor Ali is an Associate Software Engineer at Cloudways. He loves to solve technical problems through programming and mathematics.

Stay Connected:

Get Our Newsletter
Be the first to get the latest updates and tutorials.

THERE’S MORE TO READ.