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

前端 未结 7 1737
遇见更好的自我
遇见更好的自我 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:26

    IN Custom Controller

    public function login(Request $request){
    
        if (Auth::attempt(['email' => $request->email,'password' => $request->password], false)){
    
             return redirect()->intended(route('subportal.dashboard'));
        }
    
        return $this->sendFailedLoginResponse($request);
    }
    
    protected function validateLogin(Request $request)
    {
        $this->validate($request, [
            $this->username() => 'required', 'password' => 'required',
        ]);
    }
    
    /**
     * Get the login username to be used by the controller.
     *
     * @return string
     */
    public function username()
    {
        return 'email';
    }
    

    In App/Users.php

    public $table = "customer";
    protected $primaryKey = 'cust_id';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'pass', 'email','record_date',
    ];
    
    public function getAuthPassword() {
        return $this->pass;
    }
    

提交回复
热议问题