Checkout the answer over at this thread here:
https://stackoverflow.com/questions/46292391/authenticate-users-from-more-than-two-tables-in-laravel-5
Baiscally you can add multiple authentication guards and make your 3 different models that are Authenticatable. That way when you login users like:
Auth::guard('admin')->attempt($credentials)
Auth::guard('donator')->attempt($credentials)
Auth::guard('charity')->attempt($credentials)
I would probably not do it this way. Seems a lot easier to deal with one table and roles.
Another way would be to make the users table morhpable. That way you would have like: users, admin, donator, charity tables and users table would have model_id and model_type columns. Those columns are then filled with the corresponding data from either admin, donator or charity table:
// Admin user on User table
model_id = 1
model_type = "App\Admin"
// Charity on User table
model_id = 1
model_type = "App\Charity"
// Donator on User table
model_id = 1
model_type = "App\Donator"
// Then you set the relation, maybe called type so you could
// User model
public function type()
{
return $this->morphTo();
}
// Example on Admin model
public function user()
{
return $this->morphOne('App\User', 'model');
}
// Then if you wanted you could add something like isAdmin or isDonator on the User model, all you need to check if the model_type equals to whatever you expect and return true/false. That way you could allow different access to stuffs.
// So you could do
auth()->user()->type // This would then get the data from Admin, Donator or Charity table.
// Check for permissions
auth()->user()->isAdmin();
auth()->user()->isDonator();
auth()->user()->isCharity();
You can read about polymorhpic relations over here:
https://laravel.com/docs/5.8/eloquent-relationships#one-to-one-polymorphic-relations