jeudi 29 décembre 2016

Check max attempts : Laravel 5

I have a controller action method like below. Control comes in Controller code only if validations passes in Request class below.

public function Register(RegisterRequest $request) {

}

and Request class is like this

class RegisterRequest extends Request
{

    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        return [
            'Password'      => 'required',
            'EmailAddress'  => 'required',
            'UserName'      => 'required',
        ];
    }
}

Now, I am trying to write below code in case the user exceeds defined max attempts.

if ($this->hasTooManyLoginAttempts($request)) {
    return  \Response::json([
        'Status'    =>  false,
        'Message'   =>  "Attempts locked",
        'Data'      =>  null,
    ], 403);
}

I think, I should write it in Request class? but if I do so, I will need to obtain the Request class instance for hasTooManyLoginAttempts method. So, not sure how should I proceed to implement this validation

Please suggest. Here the problem is that I am not able to obtain the request class object.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire