Open terminal and run a command:
cd projectPath
php artisan make:middleware admin
go to app/Http from project folder and open kernel.php file.
inside kernel file you should add your admin middleware as route middleware:
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
'admin' => \App\Http\Middleware\admin::class,
];
make sure your user table have a field/column named "role" in your database:
Now you can modify handle function to check which role is loggedin inside newly created admin.php middleware file app/Http/middleware
public function handle($request, Closure $next)
{
return $next($request);
}