Published on January 26, 2024By DeveloperBreeze

Middleware to Restrict Access to Admins in Laravel

// 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');
}

Comments

Please log in to leave a comment.

Continue Reading:

Upload and Store File in Laravel

Published on January 26, 2024

php

Create Event and Listener in Laravel

Published on January 26, 2024

bash

Querying Data from Database Table in Laravel

Published on January 26, 2024

php

Laravel CSRF-Protected Form

Published on January 26, 2024

html

Create Resource Controller in Laravel

Published on January 26, 2024

bash

Laravel Validation Rules for User Registration

Published on January 26, 2024

php

Blade View in Laravel Extending Layout

Published on January 26, 2024

html