Ad

Method [validateUserName] Does Not Exist (Laravel 5)

- 1 answer

My code is like this :

public function postLogin(Request $request)
    {
        $this->validate($request, [
            'user_name' => 'required|user_name', 'password' => 'required',
        ]);

        $credentials = $request->only('user_name', 'password');

        if ($this->auth->attempt($credentials, $request->has('remember')))
        {
            return redirect($this->redirectPath());
        }

        return redirect($this->loginPath())
                    ->withInput($request->only('user_name', 'remember'))
                    ->withErrors([
                        'user_name' => $this->getFailedLoginMessage(),
                    ]);
    }

When I click button login, there is error message :

BadMethodCallException in Validator.php line 2615: Method [validateUserName] does not exist.

Thank you

Ad

Answer

I think what you are trying to achieve is this

$this->validate($request, [
            'user_name' => 'required',
            'password' => 'required',
        ]);

EDIT: so you are trying to login using username/password combination instead of email/password combination?

add this to your Controller/Auth/AuthController.php

protected $username = 'user_name';

but you must switch back your postLogin method to

        $this->validate($request, [
            $this->loginUsername() => 'required', 'password' => 'required',
        ]);
Ad
source: stackoverflow.com
Ad