Thursday, April 13, 2017

Laravel User with Roles, Role specific fields?

I have an application where a User can be a Supplier or a Shop. Now these 2 roles have very different role-specific fields..

Where would I put these fields for good practice?

  • Add them all on the User class, with nullable types (doesn't seem right!)
  • Create a different class for each Role. So we have a Supplier class with a user_id and Shop class with a user_id, I would have to query these fields using $user->supplier->field or $user->shop->field...

Neither of these seems like thé way to go. Any idea's? Thank you!



via Notflip

Advertisement