2016-02-27 29 views
0

目前我已經有了默認的Laravel 5.2身份驗證機制。我試圖改變這一點,以便用戶可以使用ID登錄而不是電子郵件。我不能在我的控制器中真正使用username-attribute,因爲我不希望用戶選擇該ID。我仍然想通過自動增量分配並通過電子郵件發送給他。所以我的註冊表格應該有email,passwordpassword_confirmation這兩個字段,我的登錄表單爲idpassword。 這有可能沒有重寫整個事情?我非常感謝任何幫助。謝謝!Laravel 5.2以身份而不是電子郵件登錄

回答

0

如果你去照亮\基金會\驗證\ AuthenticatesUsers你會看到laravel默認searchs領域電子郵件:

public function loginUsername() 
{ 
    return property_exists($this, 'username') ? $this->username : 'email'; 
} 

您可以像這樣在你的AuthController重寫此:

protected $username = 'id'; 

希望這會有所幫助!

+0

出於某種原因,我覺得我不能使用它,因爲它也會影響註冊。但當然你是對的!謝謝! – Sebastian

+0

它不應該影響你的註冊過程,試試看,並讓我知道。 –

0

您可以使用attempt方法,請參閱下面的代碼或this link

if (Auth::attempt(['id' => Request::input('id'), 'password' => Request::input('password')])) { 
    // Your user is logged in. 
} 
相關問題