I found the way to add an admin guard.
But there are no documentation to customize the following functionality:
Auth::guard('admin')->attempt()
Auth::guard('admin')->user()
Auth::guard('admin')->check()
middleware('auth:admin')
I need to check an additional field of admin table to check if the admin can be logged in.
In Auth::guard('admin')->attempt()
, I want to use SQL like this:
Admin::where('login_id', $request->input('login_id'))
->where('password', md5($request->input('password')))
->where('additional_field', [additional condition]);
By Auth::guard('admin')->user()
, I want to get the result of SQL like this:
Admin::where('id', Auth::guard('admin')->id())
->where('additional_field', [additional condition]);
And both Auth::guard('admin')->check()
and middleware('auth:admin')
also should consider the additional condition in the code above.
Is there a way to customize them?
And, are there any other functionalities of Laravel's auth which I have to customize to satisfy the requirement of the additional condition above?
I'm using Laravel 8.
CodePudding user response:
IF your additional stuff
are some input like login_id
and password
maybe this should work.
$cradentials= $request->only('email','password','additional stuff');
if( Auth::guard('admin')->attempt($cradentials) ){
//stuff here
}