I can't seem to put my finger on this issue. I set up a typical users and admin multi login for a laravel 7 app. When logging in with the first admin that I registered everything works fine. However, if I register more admins in the admins table, even thought Auth::guard('admin')->attempt works, the login is lost at redirect and sends to the login form again.
I pinpointed the problem which seems to be related to admin id. Any record with id=1 works, any other won't. I tried adding protected $primaryKey = 'id' to the model, and still it won't work. Could someone make sense of this and help figuring it out?
public function adminLogin(Request $request)
{
$this->validate($request, [
'email' => 'required|email',
'password' => 'required|min:6'
]);
if (Auth::guard('admin')->attempt(['email' => $request->email, 'password' => $request->password], $request->get('remember'))) {
Auth::login(Admin::where('email', $request->email)->first()); // It's only working for id=1 and it only works if I add Auth::login manually
return redirect()->intended(route('admin.dashboard'));
}
return back()->withInput($request->only('email', 'remember'));
}