We have to follow the below steps
First, we have to create a table by using the below command in which we will store the roles
php artisan make: migration create_admins_table --create=admins
after creating the migration, we will add the columns
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken(); // I put this linke incase if it was missing
then we will run the migration
php artisan migrate
then we will run the below command
php artisan make: model Admin
do not forget to add the below code in the admin.php model if there aren't
protected $guard = 'admin';
protected $fillable = [
'name', 'email', 'password',
];
we have to set up our guard in the config/auth.php file
right after the guards, we should add the below code
'admin' => [
'driver' => 'session',
'provider' => 'admins',
],
'admin-api' => [
'driver' => 'token',
'provider' => 'admins',
],
right after the provider, we should add the below code
'admins' => [
'driver' => 'eloquent',
'model' => App\Admin::class,
],
let's create controller
php artisan make: controller AdminController
let's create a view called admin and route in the web.php
Route::get()'/admin',AdminController@index)
and add the below code in the admin controller
public function __construct()
{
$this->middleware('auth:admin');
}
You can insert user roles in the table (Admin, Maker, Approver, Viewer) and direct it to views that you want