I build a SPA with vue.js 2 for the frontend and Laravel as Backend API. Now I try to implement a validation if the user failed to sign in more than three times.
So I added a column 'login_attempts' (int) for my user's table. My problem is that I don't know how to get the 'login_attempts' value with Eloquent ORM in my laravel backend.
Also, I want to increase/reset that value if further validation of the login attempt has failed/passed.
// UserController.php
public function signin(Request $request) {
$credentials = $request->only('email', 'password');
$email = $request->input('email');
// Check if login attempts above 3
// Here I need to get the 'login_attempts' value
$loginAttempts = App\User::where('email', $email)->value('login_attempts');
if($loginAttempts >= 3){
// Response: To many attempts
}
try{
// Some JWT Auth validation
}
} catch (JWTException $e) {
// Increase failed login counter
// $attemptedUser-> <--- Here i need to increase the 'login_attempts' for the user with the email of the login request
$attemptedUser->save();
}
// Some more validation and response
}
Thanks for any help.