I am getting an error Trying to get property 'account_status' of non-object. How will i fixed it. Actually I was trying to do that if account_status == 1 then i can able to login otherwise not.
public function login(Request $request){
$account_status=Auth::user()->account_status;
if($account_status == 1){
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 if(Auth::attempt(['phone' => request('phone'), '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);
} }
}
please help me out to solve this problem. I will be very grateful to you Thank you
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire