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

问题描述 投票:0回答:2

我遵循从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(),
    ]);

}

我该如何解决?

laravel laravel-5 laravel-5.2 laravel-5.3
2个回答
4
投票

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

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

注意

根据你如何合并代码,方法$this->username()也可以在旧版本中用作$this->loginUsername()


1
投票

现在看到这里的任何其他人在getCredentials(Response $response)用5.3替换了credentials(Response $response)

© www.soinside.com 2019 - 2024. All rights reserved.