// Request of email and password
$credentials = request(['email', 'password']);
// Checking credentials and increasing attempt value by 1
if (!Auth::attempt($credentials)) {
User::where('email', $request->email)->update(['attempts' => 'attempts+1']);
return response()->json([
'message' => 'Unauthorized access',
], 401);
}
以上是我在 laravel 8 上尝试过的方法。问题是如果电子邮件正确且密码错误,我想将尝试列值增加一。
答案 0 :(得分:0)
if (!Auth::attempt($credentials)) {
$this->reduceAttempt($request->email);
return response()->json([
'message' => 'Unauthorized access',
], 401);
}
public function reduceAttempt($email)
{
User::where('email', $email)->update(['attempts' => DB::raw('attempts-1')]);
return $email;
}
我已经包含了 DB::raw('attempts-1')