从Laravel 5.2升级到Laravel 5.3时出现验证问题

时间:2017-02-27 11:52:58

标签: laravel laravel-5 laravel-5.2 laravel-5.3

我遵循了从laravel 5.2升级到laravel 5.3的官方指南: https://laravel.com/docs/5.3/upgrade#upgrade-5.3.0

因为我需要对默认身份验证进行一些自定义,所以我已将login功能复制到Http\Controllers\Auth\AuthController.php

现在,当我更新时,`AuthController.php'被分成几个其他文件。

我已将login功能复制到Http\Controllers\Auth\LoginController.php

现在,我在尝试登录时遇到以下错误:

  

Controller.php第82行中的BadMethodCallException:

     

方法[getCredentials]不存在。

下面的登录功能(可能无关紧要):

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

$credentials = $this->getCredentials($request);

// This section is the only change
if (Auth::validate($credentials)) {
    $user = Auth::getLastAttempted();
    if ($user->active) {
        Auth::login($user, $request->has('remember'));

        ActivityLog::add("User has successfully logged in.", $user->id);

        return redirect()->intended($this->redirectPath());
    } else {
        return redirect($this->loginPath) // Change this to redirect elsewhere
            ->withInput($request->only('email', 'remember'))
            ->withErrors([
                'active' => 'This account has been suspended.'
            ]);
    }
}

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

}

我该如何解决这个问题?

2 个答案:

答案 0 :(得分:4)

此方法只返回登录用户名(可以是用户名,电子邮件或自定义字段)和请求数据中的密码。您可以将getCredentials()来电替换为:

$request->only($this->username(), 'password');

注意

取决于您合并代码的方式,方法$this->username()也可以在旧版本中用作$this->loginUsername()

答案 1 :(得分:1)

现在其他人在这里都将呼叫getCredentials(Response $response)在{5.3中替换为credentials(Response $response)