lundi 27 mars 2017

Laravel + Vue JS: Get/store value of Eloquent Model from DB

I build a SPA with vue.js 2 for the frontend and Laraval as Backend API. Now I try to implement a validation if the user failed to sign in more than 3 times.

So I added a column 'login_attempts' (int) for my users table. My problem is, that I don't know how to get the 'login_attempts' value with Eloquent ORM in my laravel backend.

In addition 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.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2nanV0h
via IFTTT

Aucun commentaire:

Enregistrer un commentaire