Personally I use this package to handle it: https://spatie.be/docs/laravel-permission/v5/introduction
It makes it very easy to limit access to a route by either role or permission https://spatie.be/docs/laravel-permission/v5/basic-usage/middleware
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello, i've disabled new registrations on my project with the following code: Auth::routes(['register' => false]); Now i need to setup user roles, i know if i want a new role i need to add it in kernel and then in the web.php setup the routes, and i also created middleware. but it's not working as intended, because for example lets say "X" page is for admin only, and i want to make page "X" available to admin and superadmin, for example page "y" : available for superadmin only and not for admin.~ how should i do this?
@peterpan26 You dont add it on the users table. The package has its own table for these things. I recommend adding permissions to roles, and then roles to users, but you can add a permission directly to a user
https://spatie.be/docs/laravel-permission/v5/basic-usage/direct-permissions
$user->givePermissionTo('create formularios');
Or as I said the better way
$role = Role::create(['name' => 'admin']);
$role->givePermissionTo('create formularios');
$user->assignRole('admin');
Please or to participate in this conversation.