Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

harshkumar's avatar

Create roles and permissions in Laravel 8

how do we create roles and permissions and assign the role to user in laravel 8 using laravel/jetstream?

0 likes
7 replies
InfoRR's avatar

I've been struggling making Spatie work with Jetstream. Have you tried it?

harshkumar's avatar

Hello bobbybouwmann,Thanks for your reply, for a project requirement, I just need 2 types of user, first a normal user and second an admin user, with the Laravel new authorization features, how can I achieve it, sorry if this sound silly, I am new at Laravel.

unohuim's avatar

I would simply add a field to your Users table is_admin and make it boolean, if you're only ever going to have two types. Having a User method IsAdmin() would be the only thing you'll ever need.

But if you want one level up from that, you can create roles and role_user tables, with the latter being the pivot for roles and users. I'm assuming that you know how to create and implement your own middleware. If not, I find the Laravel docs outstanding and use them daily. All you need to do then is create a route middleware class DoSomething and Gate::definition to make sure the $auth()->user()-can('do-something'); So a Gate definition in the AuthServiceProvider, DoSomething middleware class, route file reference ->middleware('do.something'), and register the DoSomething::class in the kernel.php.

I'm currently looking at diving into the spatie package myself because it looks way more robust, but there's definitely going to be a bit of a learning curve to implement it. But look at its usage, you can't beat its simplicity.

3 likes
jlrdw's avatar

You could go with laravel ui, seems more flexible when a developer needs some customizing. Plus there are several articles already on doing this with ui, search medium they have a three part series on this.

Plus you can call some of the Authentication methods directly in a custom class if needed.

But I'm not sure if you are wanting two tables or how you are setting things up. But one table is all you really need, authentication for login and use authorization to determine who can do what.

An admin is just another user. So looking at it that way fortify will fit your needs.

PCodrin's avatar

Hello, if I want to create a app where you can choose at registration if you're a client or seller what should I choose? Is Jetstream Teams enough for that or do I need some package like spatie-permissions. Thanks!

Please or to participate in this conversation.