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

AbehoM's avatar

Different users profile and roles

In this website I have four different kind of users:

  • sellers
  • advertisers
  • admins
  • moderators

Each one has different profile information and for that I came up with the solution of using polymorphism, like creating a SellerProfile, AdvertiserProfile, and so on. It works like a charm.

It's really close to what this tutorial did (read for you to understand better): http://novate.co.uk/using-laravel-polymorphic-relationships-for-different-user-profiles/

The thing here is that I'm using also a package called spatie/laravel-permission that has the roles admin, seller, and the others so I can create permissions for each one.

I was thinking that I'm kinda repeating myself here as I need to create the profile for each role but also need to create the role with spatie/laravel-permission.

This way I need to create the user with the profile and also the respective role, like: SellerProfile has seller role.

Is this approach right or there's a better solution?

0 likes
3 replies
martinbean's avatar
Level 80

@zfdeveloper No, that’s how I would model it. A user is a user, so you should only have one user model. You can determine what a user can do in your application using authorisation (and roles).

For the implementation, you should only need to create the roles for the permission package once, right? Yes, you’ll need to create a profile for each user (based on the type of user they are), but if you’ve created a seller role once already then you just need to associate that role with any new users.

AbehoM's avatar

@martinbean

but if you’ve created a seller role once already then you just need to associate that role with any new users.

I mean, I can't associate this role with any new user because as I will have different forms for registration depending on the user type (as it has different profile information) I will need to assign the profile and the respective role as well. For example, if the user is on the seller registration form I will need to assign the seller profile and also the seller role, right?

martinbean's avatar

if the user is on the seller registration form I will need to assign the seller profile and also the seller role, right?

@zfdeveloper Right. But you wouldn’t be creating the role again; just assigning a previously-created one?

$role = Role::find('seller');

$user->attachRole($role);

Please or to participate in this conversation.