2016-11-16 133 views
1

因此,我正在laravel 5.3中創建一個項目,並試圖修改我的登錄名時偶然發現了錯誤。Laravel將用戶名覆蓋到另一列不起作用

正如標題所說,我正在嘗試使用不同的列而不是'email'登錄,因爲我想爲每個用戶發送3封電子郵件。所以起初我只想改變用戶名從哪裏來。我已經做了以下。

我編輯了config/auth.php文件傾聽另一種模式是這樣的:

'providers' => [ 
    'users' => [ 
     'driver' => 'eloquent', 
     'model' => App\Models\Guest::class, 
    ] 
] 

並以我LoginController.php文件,我重寫功能的用戶名與此:

public function username() 
{ 
    return 'email1'; 
} 

這不給我有任何錯誤,但如果我嘗試使用我的數據庫中的憑據登錄,它將不會重定向。任何人都知道快速回答?謝謝!

編輯:

這裏是我的客人表的模式:

Schema::create('guests', function(Blueprint $table){ 

     $table->increments('id'); 
     $table->string('hash')->nullable(); 
     $table->string('password', 60)->nullable(); 
     $table->rememberToken(); 
     $table->string('ip')->nullable(); 

     $table->integer('reunion_id')->unsigned(); 
     $table->string('last_name'); 
     $table->string('middle_name')->nullable(); 
     $table->string('nickname')->nullable(); 
     $table->string('first_name'); 
     $table->string('initials')->nullable(); 
     $table->string('sex')->nullable(); 
     $table->date('birthdate')->nullable(); 
     $table->string('address')->nullable(); 
     $table->string('postcode')->nullable(); 
     $table->string('city')->nullable(); 
     $table->string('location')->nullable(); 
     $table->string('country')->nullable(); 
     $table->string('mobile1')->nullable(); 
     $table->string('mobile2')->nullable(); 
     $table->string('mobile3')->nullable(); 
     $table->string('phone1')->nullable(); 
     $table->string('phone2')->nullable(); 
     $table->string('phone3')->nullable(); 
     $table->string('email1')->nullable()->unique(); 
     $table->string('email2')->nullable(); 
     $table->string('email3')->nullable(); 
     $table->integer('graduation')->nullable(); 
     $table->string('level')->nullable(); 
     $table->boolean('deceased')->nullable(); 
     $table->text('comment')->nullable(); 
     $table->string('linkedin')->nullable(); 
     $table->string('facebook')->nullable(); 
     $table->string('twitter')->nullable(); 
     $table->string('instagram')->nullable(); 
     $table->boolean('found')->default(false); 
     $table->boolean('claimed')->default(false); 
     $table->boolean('confirmed')->default(false); 
     $table->boolean('ticket')->default(false); 

     $table->timestamps(); 

    }); 

我意識到,表名是客人和模型客人,但請相信我,他們連接

+0

當您嘗試登錄時發生了什麼? '客人'模型中有什麼? – GiuServ

+0

@GiuServ請看編輯文件,沒有發生任何事情。它只是刷新頁面出於某種原因,它不會重定向到錯誤或正確.. – Hoffie

+0

好@Hoffie,但是客戶擴展'Authenticatable'類? – GiuServ

回答

0

我用下面的代碼覆蓋LoginController中的登錄方法解決了我的問題。我知道這不是一個很好的做法,但如果有人知道更好的方法,請分享它。

public function login(Request $request) 
{ 

    $email = $request->all()['email']; 
    $password = $request->all()['password']; 

    if (Auth::attempt(['email1' => $email, 'password' => $password])) { 
     // Authentication passed... 
     return redirect()->intended($this->redirectPath()); 
    } 

    return $this->sendFailedLoginResponse($request); 
}  
+1

你也可以使用'$ request-> input('email')' – GiuServ