If you have only two roles you could create a model which extends the User model for each of them. Here is a example: https://tighten.co/blog/extending-models-in-eloquent.
Mar 26, 2018
6
Level 1
Login a user and assign him a model based on a role field on the users table
Hi, I am trying to create a custom login, where after logging in the user gets assigned a custom model that inheritance the default User model based on a "role" field on the users' table, the reason is that each model has its own relations.
I started by adding custom guards:
'teacher' => [
'driver' => 'session',
'provider'=> 'teachers',
],
'student'=> [
'driver' => 'session',
'provider'=> 'students',
]
and providers:
'teachers' => [
'driver' => 'eloquent',
'model' => App\Teacher::class,
],
'students' => [
'driver' => 'eloquent',
'model'=> App\Student::class,
],
I don't exactly know what to do next, how to create a custom controller that assign a logged in user a Teacher or Student based on the "role" field of the users table?
Please or to participate in this conversation.