Hello -
As I understand user, teacher, guardian models will have different relationships with other models, such as teachers will have many subjects and classes, students will belong to guardian, etc... and all those three types of users should have different fields in DB tables.
To avoid multi auth you still can have only one User auth model with some kind of a proxy relationship ->data() that will return particular user - weather teacher, guardian or student.
Here's how you can accomplish this:
This will be your user migration ( added column called type that will store fully qualified path to the particular user model class ).
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->string('type')->default(\App\Teacher::class);
$table->rememberToken();
$table->timestamps();
All involved models with set relationships:
class User extends Model
{
public function data()
{
return $this->hasOne($this->type);
}
}
class Teacher extends Model
{
public function user()
{
return $this->belongsTo(User::class);
}
public function subjects()
{
return $this->belongsToMany(Subject::class);
}
}
class Student extends Model
{
public function user()
{
return $this->belongsTo(User::class);
}
public function guardian()
{
return $this->belongsTo(Guardian::class);
}
}
class Guardian extends Model
{
public function user()
{
return $this->belongsTo(User::class);
}
public function students()
{
return $this->hasMany(Student::class);
}
}
And an example of how you'll use that kind of setup:
$teacher = new User(['type' => Teacher::class]);
$teacher->data()->create([
'teacher_name' => 'john doe',
// ...
// some other properties related specifically to teacher
]);
$teacher->data()->subjects()->createMany([
new Subject(),
new Subject(),
new Subject(),
]);
$guardian = new User(['type' => Guardian::class]);
$guardian->data()->create([
'guardian_name' => 'jane doe',
// ...
// some onther properties related specifically to guardians
]);
$guardian->data()->students()->createMany([
new User(['type' => Student::class]),
new User(['type' => Student::class]),
new User(['type' => Student::class]),
]);