Laravel: How can i change the default Auth Password field name

前端 未结 7 1713
遇见更好的自我
遇见更好的自我 2020-11-27 06:08

I\'m currently working on my first laravel project and i\'m facing a problem.

If you have experience with laravel you probably know that by calling php artisan

7条回答
  •  孤城傲影
    2020-11-27 06:28

    In the app/Http/Controllers/Auth/LoginController override the default class by adding:

    /**
     * Validate the user login request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return void
     */
    protected function validateLogin(Request $request)
    {
        $this->validate($request, [
            $this->username() => 'required', 'passwd' => 'required',
        ]);
    }
    

    Don't forget to add use Illuminate\Http\Request;

    It could be you have to add this too to your LoginController.

    /**
         * Get the needed authorization credentials from the request.
         *
         * @param  \Illuminate\Http\Request  $request
         * @return array
         */
        protected function credentials(Request $request)
        {
            return $request->only($this->username(), 'passwd');
        }
    

    That should do it.

提交回复
热议问题