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

Step2- Create Laravel New Project write this command
composer create-project --prefer-dist laravel/laravel devopsschool "5.8.*"

Step3- Move to project directory on git bash
cd devopsschool

Step4- For User Authentication write this command
php artisan make:auth

Step5- customize users table(database/migration/2014_10_12_000000_create_users_table.php)
Add Some columns in users table.
<?php | |
$table->increments('id'); | |
$table->bigInteger('role_id'); | |
$table->string('name'); | |
$table->string('email')->unique(); | |
$table->timestamp('email_verified_at')->nullable(); | |
$table->string('password'); | |
$table->rememberToken(); | |
$table->timestamps(); | |
?> |

Step6- Create Model and Migration for Role Table
php artisan make:model Role -m

Step7- customize roles table(database/migration/2020_06_10_060108_create_roles_table)
Add Some columns in roles table.
<? | |
$table->bigIncrements('role_id'); | |
$table->string('role_name'); | |
$table->string('role_slug'); | |
$table->timestamps(); | |
?> |

Step8- Make Relationship between users and roles tables through Role Model and User Model.
Step8(A)- In Role Model Create users() function for relationship.
<? | |
public function users() | |
{ | |
return $this->hasMany('App\User'); | |
} | |
?> |

Step8(B)- In User Model Create roles() function for relationship.
<? | |
public function roles() | |
{ | |
return $this->belongsTo('App\Role'); | |
} | |
?> |

Step9- Create UsersTableSeeder file for insert data in users table through migration.
php artisan make:seed UsersTableSeeder

Step10- Create RolesTableSeeder file for insert data in users table through migration.
php artisan make:seed RolesTableSeeder

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;
Step11(B)- Add Insert Function in run() function of RolesTableSeeder.php.
<? | |
DB::table('roles')->insert([ | |
'role_name' => 'Admin', | |
'role_slug' => 'admin', | |
]); | |
DB::table('roles')->insert([ | |
'role_name' => 'User', | |
'role_slug' => 'user', | |
]); | |
DB::table('roles')->insert([ | |
'role_name' => 'Manager', | |
'role_slug' => 'manager', | |
]); | |
?> |

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;
Step12(B)- Add Insert Function in run function of UsersTableSeeder.php.
<? | |
DB::table('users')->insert([ | |
'role_id' => '1', | |
'name' => 'Admin', | |
'email' => 'admin@gmail.com', | |
'password' => bcrypt('pass@admin'), | |
]); | |
DB::table('users')->insert([ | |
'role_id' => '2', | |
'name' => 'User', | |
'email' => 'user@gmail.com', | |
'password' => bcrypt('pass@user'), | |
]); | |
DB::table('users')->insert([ | |
'role_id' => '3', | |
'name' => 'Manager', | |
'email' => 'manager@gmail.com', | |
'password' => bcrypt('pass@manager'), | |
]); | |
?> |

Step13- Create Database in Mysql Server

Step14- Set Mysql Server Username ,Password and Database Name in .env file
DB_DATABASE = devopsschool | |
DB_USERNAME = root | |
DB_PASSWORD = |

Step15- Migration of Tables in Database
php artisan migration

Step16- Define UsersTableSeeder and RolesTableSeeder Class on DatabaseSeeder.php file(database/seeds/DatabaseSeeder.php)
public function run() | |
{ | |
$this->call(UsersTableSeeder::class); | |
$this->call(RolesTableSeeder::class); | |
} |

Step17- Insert data in tables
php artisan db:seed

Step18- Create DashboardController for Admin Dashboard work.
php artisan make:controller Admin/DashboardController

Step19- Create DashboardController for User Dashboard work.
php artisan make:controller User/DashboardController

Step20- Make AdminMiddleware for Admin Authentication work
php artisan make:middleware AdminMiddleware

Step21- Make UserMiddleware for User Authentication work
php artisan make:middleware UserMiddleware

Step22- Implement condition for Admin login in AdminMiddleware(app/Http/AdminMiddleware.php)
Step22(A) β Use Auth class for Authentication in AdminMiddleware.php
use Auth;

Step22(B)- Implement Condition in handle() function of AdminMiddleware.php
if(auth::check() && Auth::user()->role_id == 1){ | |
return $next($request); | |
} | |
else { | |
return redirect()->route('login'); | |
} |

Step23- Implement condition for User login in UserMiddleware(app/Http/UserMiddleware.php)
Step23(A)- Use Auth class for Authentication in UserMiddleware.php
use Auth;

Step23(B)- Implement Condition in handle() function of UserMiddleware.php
<? | |
public function handle($request, Closure $next) | |
{ | |
if(auth::check() && Auth::user()->role_id == 2){ | |
return $next($request); | |
} | |
else { | |
return redirect()->route('login'); | |
} | |
} | |
?> |

Step24- Implement Condition for Admin and User Login in RedirectIfAuthenticated(app/Http/Middleware/RedirectIfAuthenticated.php)
<? | |
public function handle($request, Closure $next, $guard = null) | |
{ | |
if (Auth::guard($guard)->check() && Auth::user()->role_id == 1) { | |
return redirect()->route('admin.dashboard'); | |
} elseif(Auth::guard($guard)->check() && Auth::user()->role_id == 2){ | |
return redirect()->route('user.dashboard'); | |
} else { | |
return $next($request); | |
} | |
} | |
?> |

Step25- Implement Condition Login in LoginController(app/Http/Controllers/Auth/LoginController.php)
Step25(A)- remove = β/homeβ from protected $redirectTo = β/homeβ;

Step25(B)- Implement Condition in __construct() function
<? | |
public function __construct() | |
{ | |
if(Auth::check() && Auth::user()->role_id == 1){ | |
$this->redirectTo = route('admin.dashboard'); | |
} elseif(Auth::check() && Auth::user()->role_id == 2){ | |
$this->redirectTo = route('user.dashboard'); | |
} | |
$this->middleware('guest')->except('logout'); | |
} | |
?> |

Step26- Implement Condition Login in ResetPasswordController(app/Http/Controllers/Auth/ResetPasswordController.php)
Step26(A)- remove = β/homeβ from protected $redirectTo = β/homeβ;

Step26(B)- Implement Condition in __construct() function
<? | |
public function __construct() | |
{ | |
if(Auth::check() && Auth::user()->role_id == 1){ | |
$this->redirectTo = route('admin.dashboard'); | |
} elseif(Auth::check() && Auth::user()->role_id == 2){ | |
$this->redirectTo = route('user.dashboard'); | |
} | |
$this->middleware('guest')->except('logout'); | |
} | |
?> |

Step27- Define AdminMiddleware in routeMiddleware(app/Http/Kernel.php)
Step27(A)- use AdminMiddleware in Kernel.php File
use App\Http\Middleware\AdminMiddleware;

Step27(B)- Define AdminMiddleware in routeMiddleware
'admin' => AdminMiddleware::class,

Step28- Define UserMiddleware in routeMiddleware(app/Http/Kernel.php)
Step28(A)- use UserMiddleware in Kernel.php File
use App\Http\Middleware\UserMiddleware;

Step28(B)- Define UserMiddleware in routeMiddleware
'user' => UserMiddleware::class,

Step29- Set Middleware and Route in web.php (route/web.php)
Step29(A)- Set Admin Middleware and Route
<? | |
Route::group(['as'=>'admin.','prefix' => 'admin','namespace'=>'Admin','middleware'=>['auth','admin']], function () { | |
Route::get('dashboard', 'DashboardController@index')->name('dashboard'); | |
}); | |
?> |

Step29(B)- Set User Middleware and Route
Route::group(['as'=>'user.','prefix' => 'user','namespace'=>'User','middleware'=>['auth','user']], function () { | |
Route::get('dashboard', 'DashboardController@index')->name('dashboard'); | |
}); |




Iβm a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I am working at Cotocus. I blog tech insights at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at I reviewed , and SEO strategies at Wizbrand.
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND