如何在laravel身份验证中处理列,用户名和密码的自定义名称

man*_*ril 2 laravel laravel-4

我有一个名为logindetials以下列的表

Login_Id | Login_Name | Login_Passwor | Login_Email | .......
Run Code Online (Sandbox Code Playgroud)

当我尝试进行身份验证时,会导致错误,如下所示

Illuminate \ Database \ QueryException
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'username' in 'where 
clause' (SQL: select * from `logindetails` where `username` = admin limit 1)
Run Code Online (Sandbox Code Playgroud)

我在config/auth.php中试过这些

'table' => 'logindetails',
'username' => 'Login_Name',
'password' => 'Login_Passwor', 
Run Code Online (Sandbox Code Playgroud)

并在models/User.php中

protected $fillable=array('Login_Name','Login_Passwor','Login_Email',...);
protected $primaryKey = "Login_Id";
protected $table = 'logindetails';
protected $hidden = array('Login_Passwor');
public function getAuthIdentifier()
{
    return $this->getKey();
}
public function getAuthPassword()
{
    return $this->Login_Passwor;
}
public function getReminderEmail()
{
    return $this->Login_Email;
}
Run Code Online (Sandbox Code Playgroud)

以及登录控制器

if (Input::server("REQUEST_METHOD") == "POST") {

  $validator=Validator::make
            (Input::all(), ["userid" => "required","password" => "required"]);
  if ($validator->passes()) {

     $credentials = [
          "Login_Name" => Input::get("userid"),
          "Login_Passwor" => Input::get("password")];
     if (Auth::attempt($credentials)) {
          return Redirect::route("/");
     }

  }
  $data["errors"] = new MessageBag(["password" => 
                     ["Username and/or password invalid."]]);
  $data["Login_Name"] = Input::get("userid");
  return Redirect::route("login")->withInput($data);

}
Run Code Online (Sandbox Code Playgroud)

但没有raksha.请有人帮我解决这个问题

小智 5

实际上还有其他可以保留自定义密码字段的使用方法.

只需遵循:

假装您希望自定义密码密码为"Login_Passwor".为此,只需在models\User.php中添加一个函数,如下所示

public function getAuthPassword() 
{
   return $this->Login_Passwor; 
}
Run Code Online (Sandbox Code Playgroud)

现在,在您的登录控制器中,只需对Auth进行此更改:尝试

$credentials = ["Login_Name" => Input::get("userid"),
                "password" => Input::get("password")];

if (Auth::attempt($credentials)) 
{
    return Redirect::route("/");
}
Run Code Online (Sandbox Code Playgroud)

这个方法肯定会起作用,试过了