nazimfeni liked this thread
Yes, you are right. In Laravel 11, kernel.php is removed. The solution might be in three steps:
In your config/auth.php file, define separate guards for each user type. For example: `'guards' => [ 'web' => [ 'driver' => 'session', 'provider' => 'users', ], 'admin' => [ 'driver' => 'session', 'provider' => 'admins', // Assuming a separate provider for admins ], ],
`
Create Middleware: Create custom middleware classes for each guard. For instance: PHP `// app/Http/Middleware/AuthAdmin.php class AuthAdmin { public function handle($request, Closure $next, $guard = 'admin') { if (Auth::guard($guard)->check()) { return $next($request); }
return redirect('admin/login'); // Redirect to admin login route
} }
// app/Http/Middleware/AuthWeb.php (Similar structure for web users) `
In your routes/web.php file, use the middleware to protect routes based on the guard: PHP `Route::middleware(['auth:web'])->group(function () { // Routes accessible to web users });
Route::middleware(['auth:admin'])->group(function () { // Routes accessible to admins });`
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community