I have been trying to find the best solution for using multiple user types. I have two models, a Teacher Model and a User model that I am using for the student. I connect the two with a belongsToMany relationship and it works well for what I am trying to build. I can grab all the teacher's students with something like $teacher->users and I like being able to do that. The two tables also have different fields. I also have a third Model/Table called Conversation and both a Teacher and a User are tied into that within the Conversation model with hasOne(Teacher::class) and hasOne(User::class). So for so good. Everything is working, but I am starting to read that people really prefer using roles and permission on the user table. Ideally, I want to have just a Student model/table and teacher Model/Table because "user" is throwing me off.
If I use roles how would I associate which Teachers have which students. I personally don't want to use roles, but if this is what is recommended I will switch over, but I am just not sure which route to take.
Still trying to figure this out. If I create a Role model and assign a user a role of a teacher or student, what would be the easiest way to connect two users? This is what I really need to figure out. Seems easier to just use two different models.
I usually prefer managing two different models if the system will not require more in a future. A multi-auth can be implement using different providers or using the same provider and change its model on AuthServiceProvider (auth()->getProvider()->setModel($model)).
If you end up implementing roles, in order to associate them you may create an scope under the user model and make the appropriate query builder to return only the users of role X or Y.
You mention a conversation, with the roles implementation it can be more flexible, you may have students talking to students, or student to ANY kind of user. With the first approach I think you may need to use some kind of polymorphic relation to have any to any conversations.
I appreciate your reply. I have attempted to get multi-auth to work with Laravel 5.3 and I have failed. Any more information on how to get it working? I've tried to follow 2-3 guides for 5.2, but I just never got it to work.
Did you ever come to a good solution for this? My first thought when reading the thread would be to keep your users tied to the authentication, but then have a Teacher model and a Student model that each have a hasOne(User::class), this way you don't have to mess with the underlining authentication in Laravel but are able to keep teachers and students separate and can have things like belongsTo(Teacher::class) on your Student model and hasMany(Student::class) on your Teacher model.
This would allow you to easily extend the User model with something like isTeacher and/or isStudent
I personally would consider let the teacher and student as User as they are really a user and may have a user group or user type to differentiate them, and probably will create a "Class" or "Subject/Lesson" so that the "Class/Subject" will have 1 teacher and many students, probably this way, teacher may or may not teach more than one "Class" and student also can attend more "class/subject" and so on.
Depending on your app, but multi-auth can be very complicated.
In my case, I had users and trainers. They both can submit a post (e.g. forum posts).
If you have two different models you need to check if a current user is a trainer or not if so, fill a trainer_id column and so on.
And that kind of logic occurs everywhere in my app. So, I ended up extending User model and create Trainer model using hasOne(User::class) and associate other models with just user_id , and separate all trainer specific logics on Trainer model.