lifesound's avatar

Validate another input to Login

How could i add another input to laravel authentication

Like Store_id with email and password

Not asking about the html

I'm asking about the validation

the store_id have to be exists in the stores table

How i can add that .. because in the AuthController , I found only the validation for the registeration

    /**
 * Get a validator for an incoming registration request.
 *
 * @param  array  $data
 * @return \Illuminate\Contracts\Validation\Validator
 */
protected function validator(array $data)
{
    return Validator::make($data, [
        'name' => 'required|max:255',
        'email' => 'required|email|max:255|unique:users',
        'password' => 'required|confirmed|min:6',
    ]);
}

And After that i need to add the store_id to the session ..

thx

0 likes
10 replies
d3xt3r's avatar

You can additional fields from user table but you can't add fields from other table. You, however, can intercept the authentication process and do whatever check you want in the authenticated method in the auth controller.

AuthController.php 

protected function authenticated(Request $request, $user)
 {
    // Once the guard authenticates your user, he will land up here
    // Do whatever check you require and feel free to log him out if required 
    // but with proper redirection and error message
    
    // if valid add whatever details wherever and 
    return redirect()->intended($this->redirectPath());
}
1 like
SaeedPrez's avatar
Level 50
    /**
     * Validate the user login request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return void
     */
    protected function validateLogin(Request $request)
    {
        $this->validate($request, [
            $this->loginUsername() => 'required', 'password' => 'required',
        ]);
    }

This is Laravel's validateLogin() method which you can overwrite in your AuthController.php.

1 like
lifesound's avatar

where is the location to put (seesion::put(location))

SaeedPrez's avatar

@lifesound look at @d3xt3r's first reply, if you create that method in your AuthController, it will will overwrite Laravel's default actions after user is authenticated.

1 like
lifesound's avatar

@d3xt3r i didn't found this method L5.2

May be this handleUserWasAuthenticated I understand that i have to add it thx

lifesound's avatar

As note , the property have to be added to User model as fillable

Please or to participate in this conversation.