Creating Laravel Multiple Authentication System Using Default Authentication System in Laravel 5.4

In this tutorial we are going to build multiple authentication system in Laravel 5.4 without using packages. We are going to build this system in a simple, clean and in a way that is natural to Laravel, we will be extending what we do when we run this command: php artisan make:auth

We are going to have two different tables, one for users and one for admins. Don’t get confused between type of users and role of users. A good example of user role based system is WordPress, where we have admins, contributors, editors, authors. All of them are admins but they have different level of authority in the system.

A good example of the use case that we are going to create in this system is an e-commerce website, on one side we have admins who can create products, issue refunds, order stock, manage orders: the admins manage the website. On the the other side, we are going to have users/customer who will have order history, wish list etc. Both the admins and user/customer’s have their own different interface which have different functionalities. Basically, that’s how they manage their account’s.

Let’s  Code! Creating Laravel Multiple Authentication System

We are going to start with new Laravel project, I have Laravel installer on my computer. To create a new project I just have to run this command on my terminal: laravel new Laravel-Multiple-Auth I am going to call my project Laravel-Multiple-Auth.

The first thing that we need to do is to connect our project to database. In this tutorial, I will be using MySQL. I have created a database named multi_auth on PhpMyAdmin. Now open .env file and add our database connection:

The next step is to create user authentications scaffold using one simple command. On you terminal run the following command:php artisan make:auth This command basically install layout view, registration and login views, as well as routes for all authentications end-points. A HomeController is also generated to handle post-login requests to your application’s dashboard.

Before we run our migrations, we need to create a new table for admins. Lets create migration for that by running this command: php artisan make:migration create_admins_table –create=admins

Now open our new migration by navigating to /database/migrations and open admin migration, add the following code:

To run our migrations, we use the following command: php artisan migrate

Lastly, in this lesson lets run our application using the following command: php artisan serve and visit our browser: You should be able to see the following screen.

In the next lesson, we will start by creating our guards. To get the code for this tutorial visit Laravel 5.4 Multi Authentication System


              Get started with Part 2: Creating Our Admin Model and Admin Guard. 

Facebook Comments
Get free email updates!
Signup now and receive an email once we publish new content.
We respect your privacy

Henry Mbugua

I am a Junior Developer ready to enter major leagues. My professional ambition is to stay versatile and be able to fill different roles within a product group. As such, I have been learning technology across frontend and backend.