Guards are always problematic and should be avoided.
Log in with two different models
I have two models that i want to authenticate with and log in. The user model and the stations model! I wrote this code here located in JestreamServiceProvider:
Fortify::authenticateUsing(function (Request $request) {
$user = User::where('email', $request->identifier)->first();
$station = Station::where('username', $request->identifier)->first();
if ($user && Hash::check($request->password, $user->password)) {
return $user;
}
if ($station && Hash::check($request->password, $station->password)) {
return $station;
}
return null;
});
Both users and stations log in from the same login page. i successfully authenticate using the stations username and password but it logs me in as a user! Its like it takes the id from the station and proceeds to log in with user using the stations id for users id or something like that. Can anyone help me how to use two different models to authenticate and log in? i already have set up in the config/auth.php guards and providers for users and stations like this:
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'stations' => [
'driver' => 'session',
'provider' => 'stations',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
'stations' => [
'driver' => 'eloquent',
'model' => App\Models\Station::class,
],
],
Please or to participate in this conversation.