public function login(Request $request)
{
$user = User::where('email', $request->emailOrPhone)
->orWhere('phone', $request->emailOrPhone)
->first();
if($user){
if (Hash::check($request->password, $user->password)) {
$tokenResult = $user->createToken('Personal Access Token');
$token = $tokenResult->token;
if ($request->remember_me)
$token->expires_at = Carbon::now()->addWeeks(1);
$token->save();
return response()->json([
'access_token' => $tokenResult->accessToken,
'expires_at' => Carbon::parse(
$tokenResult->token->expires_at
)->toDateTimeString()
]);
} else {
$response = ['Password incorrect'];
return response($response, 422);
}
}else {
$response = ['User does not exist'];
return response($response, 422);
}
}