this is my login logic when i try it give me error down blow
public function login(Request $request)
{
$request->validate([
'Email'=>'required',
'password'=> 'required'
]);
$agent = DB::table('agents')->where('Email',$request->Email)->first();
if($request->password == $agent->password || Hash::check($request->password,$agent->password))
{
Auth::login($agent);
return redirect()->route('agent.index');
}
else
{
return dd('no');
}
The Error :
IlluminateAuthSessionGuard::login(): Argument #1 ($user) must be of type IlluminateContractsAuthAuthenticatable, AppModelsagent given, called in C:xamppshtdocsLaravelLaravel-10REVvendorlaravelframeworksrcIlluminateAuthAuthManager.php on line 340
i new to laravel so i did not try much cause i know very little about authentication and login logic also how to deal with middleware
so please if u dont have answer to my question i need help on from where i could know more about auth and middleware and deg deeper in Laravel beside the documentation
2
Answers
You can’t use the
agents
model or the table to authenticate users straight out of the box.According to the Laravel documentation:
This means that Laravel uses the
User
model to authenticate users. So, you could stick with theUser
model that Laravel comes with or customize the default authentication driver to fit your needs. I’d recommend sticking with the default authentication driver, but it’s ultimately up to you.You can take a look at these references for how to create a custom authentication guard.
Laravel official documentation
How to use auth guard in laravel
I’m not entirely sure why you’re searching for the Agent model first, but you should follow these steps:
After retrieving your agent, you need to find the User model because the login method expects an object of the User model.