MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

How to Create Multiple Role Based Authentication and Access Control in Laravel Application

Step1- Open command prompt or Git Bash on xampp/htdocs directory

Git Bash window opened in the xampp/htdocs folder, with the path highlighted in Explorer and terminal

Step2- Create Laravel New Project write this command

composer create-project --prefer-dist laravel/laravel devopsschool "5.8.*"Code language: JavaScript (javascript)
Git Bash running composer create-project to install Laravel 5.8 as the devopsschool project

Step3- Move to project directory on git bash

cd devopsschool
Git Bash after cd devopsschool, prompt now showing the c/xampp/htdocs/devopsschool path

Step4- For User Authentication write this command

php artisan make:authCode language: CSS (css)
Git Bash running php artisan make:auth with Authentication scaffolding generated successfully

Step5- customize users table(database/migration/2014_10_12_000000_create_users_table.php)

Add Some columns in users table.

Create_users_table migration in the editor with a role_id bigInteger column added to the users schema

Step6- Create Model and Migration for Role Table

php artisan make:model Role -mCode language: CSS (css)
Git Bash running php artisan make:model Role -m, which creates the Role model and roles table migration

Step7- customize roles table(database/migration/2020_06_10_060108_create_roles_table)

Add Some columns in roles table.

Create_roles_table migration defining role_id, role_name, role_slug and timestamps columns

Step8- Make Relationship between users and roles tables through Role Model and User Model.

Step8(A)- In Role Model Create users() function for relationship.

Role.php model with a users() function returning hasMany App\User

Step8(B)- In User Model Create roles() function for relationship.

User.php model with a roles() function returning belongsTo App\Role

Step9- Create UsersTableSeeder file for insert data in users table through migration.

php artisan make:seed UsersTableSeederCode language: CSS (css)
Git Bash running php artisan make:seed UsersTableSeeder with Seeder created successfully

Step10- Create RolesTableSeeder file for insert data in users table through migration.

php artisan make:seed RolesTableSeederCode language: CSS (css)
Git Bash running php artisan make:seed RolesTableSeeder with Seeder created successfully

Step11- Add Insert function in RolesTableSeeder.php(database/seeds/RolesTableSeeder.php) file for Insert data in roles table.

Step11(A)- use DB file in RolesTableSeeder.php

use Illuminate\Support\Facades\DB;Code language: PHP (php)

Step11(B)- Add Insert Function in run() function of RolesTableSeeder.php.

RolesTableSeeder.php importing the DB facade and inserting Admin, User and Manager roles in run()

Step12– Add Insert function in UsersTableSeeder.php(database/seeds/UsersTableSeeder.php) file for Insert data in users table.

Step12(A) – use DB file in UsersTableSeeder.php

use Illuminate\Support\Facades\DB;Code language: PHP (php)

Step12(B)- Add Insert Function in run function of UsersTableSeeder.php.

UsersTableSeeder.php inserting Admin and User accounts with role_id, email and bcrypt passwords

Step13- Create Database in Mysql Server

PhpMyAdmin Databases tab with devopsschool entered as the new database name

Step14- Set Mysql Server Username ,Password and Database Name in .env file

.env file with MySQL settings: DB_DATABASE devopsschool, DB_USERNAME root and an empty password

Step15- Migration of Tables in Database

php artisan migration
Terminal running php artisan migrate, creating users, password_resets and roles tables successfully

Step16- Define UsersTableSeeder and RolesTableSeeder Class on DatabaseSeeder.php file(database/seeds/DatabaseSeeder.php)

DatabaseSeeder.php run function calling UsersTableSeeder and RolesTableSeeder

Step17- Insert data in tables

php artisan db:seedCode language: CSS (css)
Terminal running php artisan db:seed, seeding UsersTableSeeder and RolesTableSeeder successfully

Step18- Create DashboardController for Admin Dashboard work.

php artisan make:controller Admin/DashboardController
Terminal running php artisan make:controller Admin/DashboardController with controller created successfully

Step19- Create DashboardController for User Dashboard work.

php artisan make:controller User/DashboardController
Terminal running php artisan make:controller User/DashboardController with controller created successfully

Step20- Make AdminMiddleware for Admin Authentication work

php artisan make:middleware AdminMiddlewareCode language: CSS (css)
Terminal running php artisan make:middleware AdminMiddleware with middleware created successfully

Step21- Make UserMiddleware for User Authentication work

php artisan make:middleware UserMiddlewareCode language: CSS (css)
Terminal running php artisan make:middleware UserMiddleware with middleware created successfully

Step22- Implement condition for Admin login in AdminMiddleware(app/Http/AdminMiddleware.php)

Step22(A) – Use Auth class for Authentication in AdminMiddleware.php

use Auth;Code language: PHP (php)
AdminMiddleware.php in the editor with the use Auth statement added

Step22(B)- Implement Condition in handle() function of AdminMiddleware.php

AdminMiddleware handle function allowing role_id 1, otherwise redirecting to the login route

Step23- Implement condition for User login in UserMiddleware(app/Http/UserMiddleware.php)

Step23(A)- Use Auth class for Authentication in UserMiddleware.php

use Auth;Code language: PHP (php)
UserMiddleware.php in the editor with the use Auth statement added

Step23(B)- Implement Condition in handle() function of UserMiddleware.php

UserMiddleware handle function allowing role_id 2, otherwise redirecting to the login route

Step24- Implement Condition for Admin and User Login in RedirectIfAuthenticated(app/Http/Middleware/RedirectIfAuthenticated.php)

RedirectIfAuthenticated handle function sending role 1 to admin.dashboard and role 2 to user.dashboard

Step25- Implement Condition Login in LoginController(app/Http/Controllers/Auth/LoginController.php)

Step25(A)- remove = ‘/home’ from protected $redirectTo = ‘/home’;

LoginController.php with protected $redirectTo declared without the /home value

Step25(B)- Implement Condition in __construct() function

LoginController constructor setting redirectTo to admin or user dashboard based on role_id

Step26- Implement Condition Login in ResetPasswordController(app/Http/Controllers/Auth/ResetPasswordController.php)

Step26(A)- remove = ‘/home’ from protected $redirectTo = ‘/home’;

ResetPasswordController.php with protected $redirectTo declared without the /home value

Step26(B)- Implement Condition in __construct() function

ResetPasswordController __construct redirecting role_id 1 to admin.dashboard and role_id 2 to user.dashboard

Step27- Define AdminMiddleware in routeMiddleware(app/Http/Kernel.php)

Step27(A)- use AdminMiddleware in Kernel.php File

use App\Http\Middleware\AdminMiddleware;Code language: PHP (php)
Kernel.php with use App\Http\Middleware\AdminMiddleware statement highlighted

Step27(B)- Define AdminMiddleware in routeMiddleware

'admin' => AdminMiddleware::class,Code language: PHP (php)
Kernel.php routeMiddleware array with 'admin' => AdminMiddleware::class added

Step28- Define UserMiddleware in routeMiddleware(app/Http/Kernel.php)

Step28(A)- use UserMiddleware in Kernel.php File

use App\Http\Middleware\UserMiddleware;Code language: PHP (php)
Kernel.php with use App\Http\Middleware\UserMiddleware statement highlighted

Step28(B)- Define UserMiddleware in routeMiddleware

'user' => UserMiddleware::class,Code language: PHP (php)
Kernel.php routeMiddleware array with 'user' => UserMiddleware::class added

Step29- Set Middleware and Route in web.php (route/web.php)

Step29(A)- Set Admin Middleware and Route

Web.php admin route group with auth and admin middleware and dashboard route

Step29(B)- Set User Middleware and Route

Web.php user route group with auth and user middleware and dashboard route

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Top 10 Identity Verification (IDV) Tools: Features, Pros, Cons & Comparison

Introduction Identity Verification (IDV) tools are digital solutions designed to confirm that a person is who they claim to be. These tools typically verify government-issued identity documents,…

Read More

7 Best Vendors for Non-Human Identity Management in Agentic AI Pipelines (2027)

Your agentic pipeline just spawned a fresh fleet of sub-agents overnight. Each one grabbed a long-lived API key from a config file and started firing off tool…

Read More

Terraform Cloud (HCP Terraform) — Organization, Project, Workspace, Team & User Mapping

Updated: October 15, 2026 | Based on current HashiCorp documentation Terraform Cloud is now called HCP Terraform. Its architecture separates infrastructure organization from user access management (RBAC)….

Read More

Cloud Computing Beyond the Hype: Security, Control, and a Practical Adoption Path

Cloud computing is a long-term operating model, not a temporary trend. This revised guide explains the control trade-offs, security concerns, and a practical migration workflow teams can use today.

Read More

What Are Cloud Misconfigurations, and Why Do They Drain Their Budget?

Enterprises benefit from cloud flexibility, but it also increases the risk of errors. A cloud misconfiguration is a service, resource, authorization, or security control that’s misconfigured or…

Read More

GitHub Organization Administration Essentials — 2-Hour Tutorial

Last Verified: September 2026Based on: GitHub Organization Administration — Complete Reference Guide and TutorialDuration: 2 hoursAudience: GitHub organization owners, DevOps/platform engineers, developers with delegated administration duties, security administrators, and technical trainers….

Read More