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

Ranjeet's avatar

How to make custom Roles in Laravel

iam new to laravel and i think you will help me .I want to make a role based system in Laravel5 without using any package. One role for "admin" and another for "client" and both login through same form(auth/login.blade.php). Anybody say me how can i do this. What should i do in database,routes and other files if necessary. Thankyou

0 likes
1 reply
toniperic's avatar

@Ranjeet most common answer you'll see is use a package that suits your needs rather than re-inventing the wheel. In case you decide to develop a package for your own needs, feel free to publish it later to Packagist as others might find it useful. And we love members that share. :)

Well, I suppose you have users table and a User model, and we want to determine which user can access what resource.

You could have a role attribute assigned to each user, and store it in the users table. Given that each user can only have one role, of course. All you'd do then is have a middleware that checks whether user is an admin or a client, and protect resources with middlewares, essentially making sure that users only have ever access to resources they are supposed to.

Hope I could help.

2 likes

Please or to participate in this conversation.