DeveloperBreeze

Middleware to Restrict Access to Admins in Laravel

php
// Middleware to check if the user is an admin
public function handle($request, Closure $next)
{
    // Verify the user is authenticated and an admin
    if (auth()->check() && auth()->user()->isAdmin) {
        return $next($request);
    }

    // Redirect non-admin users to the home page
    return redirect()->route('home');
}

Continue Reading

Handpicked posts just for you — based on your current read.

Discussion 0

Please sign in to join the discussion.

No comments yet. Start the discussion!