2013-10-03 48 views
1

我有一個表單,我試圖通過使用Laravels Auth方法登錄。Auth ::嘗試將默認密碼更改爲默認字段,如DB中

目前,我有這樣的片段:

$input = Input::all(); 

$login = Auth::attempt([ 
'username' => $input['username'], 
'password' => $input['password'] 
]); 

if($login){ 
return "Logged in"; 
} 

dd('problem'); 

但是,即使輸入正確的憑據我越來越看到「問題」

型號/後user.php的我已經改變我的表名tbl_login(就像我在DB),這是我在這

,在我登錄模型做出的唯一改變我

class Login extends Eloquent { 
protected $guarded = array(); 
protected $table = "tbl_login"; 
protected $primaryKey = "pk_loginID"; 

public static $rules = array(); 
} 

我也檢查了這個topic但沒有真正幫助,我希望你們現在可以幫助我。

正如信息和阿里納斯:在DB = tbl_login表名

主鍵字段是pk_loginID

用戶名字段=用戶名

密碼字段=密碼

我是不是忘了什麼東西還是我做錯了什麼?

編輯:

我已經找到了問題的更具體的,而不是它的解決方案。我在數據庫中的密碼字段的名稱不同於Laravel使用的默認密碼字段。我怎麼能說Laravel使用我的自定義密碼字段?

+0

您同時擁有'Login'一個找到一個鏈接到'tbl_login'表的用戶模型? – rmobis

+0

是的,因爲用戶是那裏的標準,但我剛剛刪除登錄模型,但出現相同的問題 – mXX

回答

1

我發現的方法getAuthPassword()解決

User model

public function getAuthPassword() 
{ 
    return $this->attributes['passwordFieldinYourTable'];//change the 'passwordFieldinYourTable' with the name of your field in the table 
} 

就是這樣:)

+0

我的用戶表具有以下數據庫結構fld_ID,fld_Username,fld_Password'''是否有可能在用戶文件中進行更改?如何? –

+0

幫助很多。投票,以便沒有將密碼字段命名爲「密碼」的人知道該怎麼做。 –

+0

樂意幫忙! @ MehdiHosseini仍然需要幫助嗎?剛剛看到您的評論。 – mXX

0

你不能改變它,但你可能可以解決這個問題通過創建新的存取器密碼字段:

<?php 

use Illuminate\Auth\UserInterface; 
use Illuminate\Auth\Reminders\RemindableInterface; 

class User extends Eloquent implements UserInterface, RemindableInterface { 

    ... 

    public function getPasswordAttribute() 
    { 
     return $this->YourPasswordField; 
    } 

    public function setPasswordAttribute($password) 
    { 
     $this->YourPasswordField = $password; 
    } 


} 
+0

我已經在我的用戶類中添加了這種方法,但它實際上仍然是相同的。什麼也沒有變。我在密碼錶中的字段是「PASSWORD」,所以我將'$ this-> YourPasswordField'替換爲'$ this-> PASSWORD' – mXX