Dean

Two different user classes?

Posted 4 years ago by Dean

Just trying to think of how to tackle what I imagine is a fairly common occurrence.

There needs to be two different user types, because there are two different 'account areas'. For example, say we have a directory website, and we have an account area for businesses to create and maintain listings in the directory, and then an account area for customers to interact with the listings. I want to have both separate.

So the way I see it, one option is to just have a property on the User class, to define which type of user this is, but that seems like a poor solution. Another option is to have two different user classes, Customer and Business, with different tables etc., but Laravel is designed in a way that assumes only one User class for Auth purposes, so I imagine I will run into problems. Perhaps, a third option is to have a User class and then have it inherited by a Customer and a Business class, with the User class responsible just for Auth, and then the Customer and Business classes are used for any other model based logic. I'm just not sure how this will work with the Eloquent ORM.

How have others tackled similar problems?

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.