Support the ongoing development of Laravel.io →
posted 7 months ago

nazimfeni liked this thread

1

Yes, you are right. In Laravel 11, kernel.php is removed. The solution might be in three steps:

  1. Define Guards:

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 ], ],

`

  1. 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) `

  1. Protect Routes:

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 });`

Last updated by @nazimfeni 7 months ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.