Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

shami003's avatar

How to modify login api so users can also login with registration?

I want that users can login with the registration number assigned to them or email. I have working api which only login users with email

public $successStatus = 200;

public function login(){ 
    if(Auth::attempt(['email' => request('email'), 'password' => request('password')])){ 
        $user = Auth::user(); 
        $success['token'] =  $user->createToken('MyApp')-> accessToken; 
        return response()->json(['success' => $success], $this-> successStatus); 
    } 
    else{ 
        return response()->json(['error'=>'Unauthorised'], 401); 
    } 
}
0 likes
1 reply
Sergiu17's avatar
Auth::attempt([
	'email' => request('email'),
	'password' => request('password')
])

You probably hash passwords before you store them in your data base, if so, then

Auth::attempt([
	'email' => request('email'),
	'password' => bcrypt(request('password')) // hash the password, then try to login
])

Please or to participate in this conversation.