notflip's avatar

Using 3 Authenticatable entities, Seperate Auth or with User?

Hi,

Looking for some good practice advice here, I have admins, employees, and coaches. They will all have to login, but have some different data in the db, and different roles and permissions.

Is it good practice to have a Users table which holds all users, and then couple each user to it's type with a relation..

Auth::user()->admin  //would give me access to his admin specific fields. 

Or are there better options? This seems like a good one because only one table handles Authentication.

Looking forward to your responses!

0 likes
5 replies
pmall's avatar
pmall
Best Answer
Level 56

yes I would keep only one users table and use a polymorphic relationship for the user types.

1 like
martinbean's avatar

@notflip Just have a single application. You can then use relationships and roles/permissions to infer whether a user is an administrator, employee, or coach.

notflip's avatar

@pmall Could you please explain the polymorphic relation? I was just going with belongsTo, should I use the polymorphic ones?

pmall's avatar

You should check the docs about polymorphic relationships.

Basically it could allow you to have one belongTo relationship but for many different types of related models.

notflip's avatar

Thanks, I got it working, I'm just wondering.

Isn't this dangerous for getting the wrong type? I I would assume that

$user->userable->data is set, but I don't know what kind of 'userable' the User is. Do you know what I mean?

Thanks for your advice by the way!

Please or to participate in this conversation.