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

harshamv's avatar

Multiple User Authentication System

I have 3 types of users in my projects.

1. Admin (admin.domain.com)
2. Brands (brand.domain.com)
3. Users (domain.com)

Based on the DB design decision we will have 3 separate tables admins, users and brands. I need to create 3 authentication user types. The Laravel documentation was not helpful in understanding on how this can be achieved.

Coming from rails, we had a very easy way of using namespaces with the devise gem to achieve this. Is there any plugin to achieve this or any guide which I can follow to implement the same.

I am using Laravel 6.

0 likes
14 replies
jlrdw's avatar

I would have thought it would be more like:

  • Admin (domain.com/admin)
  • Brands (domain.com/brand)
  • Users (domain.com/user)

But all are users. Also look here and at other links in there. https://laracasts.com/discuss/channels/general-discussion/authorization-policies-and-reducing-the-repitition

and

https://laracasts.com/discuss/channels/laravel/security-in-controller

Usually a good RBAC with correct queries does the job.

For what you want also look at: https://github.com/spatie/laravel-permission

1 like
lightyagami's avatar

you're wasting your time, you have to use roles and permissions.

roles: admin, brands, users permissions: administrator, brand, user, guest.

you don't need separate your authentication in 3 types. that would be very dirt.

siangboon's avatar

if all user types are accessing the same resources or related, i would suggest to use singler url and control the access with the user, user group, user role and permission.

siangboon's avatar

admin.domain.com, brand.domain.com, users.domain.com are 3 different URL, usually people use different url for different projects or purposes. What i meant single url is all 3 types of users are accessing at the same login url and use the role and permission to control their access of the view and actions on to the resources accordingly.

to implement role/permission, you can refer the lessons here: https://laracasts.com/series/whats-new-in-laravel-5-1/episodes/13 https://laracasts.com/series/whats-new-in-laravel-5-1/episodes/14 https://laracasts.com/series/whats-new-in-laravel-5-1/episodes/15 https://laracasts.com/series/whats-new-in-laravel-5-1/episodes/16

1 like
harshamv's avatar

@hakhsin thanks a lot will check it out. Is it your repository? If I have any questions can I ask here?

harshamv's avatar

@siangboon thanks a lot. went through them. It is clear. In my app we will have three sub-domains itself but render the app from single source code. We have been doing the same in Rails for the last three years.

Just moving to Laravel so figuring out how to build on laravel.

harshamv's avatar

@siangboon yes was checking this out. Thanks a lot. Hope I can get this to work somehow and move on to the fun part.

jlrdw's avatar

Of course I mentioned https://github.com/spatie/laravel-permission earlier. But why can't you use the same style RBAC you used in Rails here. Nothing prevents you from using custom authentication and authorization (RBAC).

I also use cake and yii for projects thus stay away from some framework biased code. I like RBAC that can work in any language with small tweaks.

2 likes

Please or to participate in this conversation.