I am trying to add additional query conditional while authenticating a user.
I have the users table and it has the role column. I need to authenticate only specific users with the defined role.
Here is my controller method
public function login( UserAuthRequest $request ) {
$credentials = $request->only( 'login', 'password' );
if ( $token = $this->guard()->attempt( $credentials ) ) {
return $this->respondWithToken( $token );
}
return response()->json( [ 'error' => 'Unauthorized' ], 401 );
}
auth.php section
'admin-users' => [
'driver' => 'eloquent',
'model' => AdminUser::class,
],
The admin user has it's own table called admin_users with the foreign key to the users table.
As a result I get the following error
Column not found: 1054 Unknown column 'login' in 'where clause' (SQL: select * from `admin_users` where `login` = admin limit 1)"
I've tried to pass userEntity.login instead of simply login, however this didn't work.
How to solve this problem without creating custom providers?
Thx.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire