laravel 5内置脚手架试图使用用户名而不是电子邮件错误

时间:2015-05-10 15:43:28

标签: php laravel laravel-5

我已经创建了一个列用户名,并将其填入用户表中,该用户表与登录脚手架中内置的laravel 5一起使用,我正在尝试的是使用用户名代替默认电子邮件,所以我调整了代码我在laravel \ vendor \ compiled.php中找到了以下内容(参见下文)

此默认代码

public function postLogin(Request $request)
{
    $this->validate($request, array('email' => 'required|email', 'password' => 'required'));
    $credentials = $request->only('email', 'password');
    if ($this->auth->attempt($credentials, $request->has('remember'))) {
        return redirect()->intended($this->redirectPath());
    }
    return redirect($this->loginPath())->withInput($request->only('email', 'remember'))->withErrors(array('email' => $this->getFailedLoginMessage()));
}

public function postLogin(Request $request)
{
    $this->validate($request, array('email' => 'required', 'password' => 'required'));
    if ($this->auth->attempt(['username' =>  $request->input('email'), 'password' =>  $request->input('password'), $request->has('remember')])) {
        return redirect()->intended($this->redirectPath());
    }
    return redirect($this->loginPath())->withInput($request->only('email', 'remember'))->withErrors(array('email' => $this->getFailedLoginMessage()));
}

但它给我一个错误说

  

Connection.php第620行中的QueryException:   SQLSTATE [42S22]:未找到列:1054'where子句'中的未知列'0'(SQL:select * from dodong_users其中username = dodong@dodong.com和0 = 0限制1)

任何帮助,建议,推荐,线索,解决此问题的想法,以便我可以使用用户名而不是电子邮件登录将非常感谢。谢谢!

1 个答案:

答案 0 :(得分:0)

改变这个:

if ($this->auth->attempt(['username' =>  $request->input('email'), 'password' =>  $request->input('password'), $request->has('remember')])) {

对此:

if ($this->auth->attempt(['username' =>  $request->input('email'), 'password' =>  $request->input('password')], $request->has('remember'))) {

看起来你只是把$request->has('remember')放在了错误的地方。它正在寻找名为0的列,因为您将$request->has('remember')的值作为attempt()数据的一部分传递。

要使用documentation中的示例,您正在执行此操作:

if (Auth::attempt(['email' => $email, 'password' => $password, $remember]))
{
    // The user is being remembered...
}

当你应该这样做的时候:

if (Auth::attempt(['email' => $email, 'password' => $password], $remember))
{
    // The user is being remembered...
}