2016-11-16 6 views
1

私はlaravel 5.3でプロジェクトを作成しています。ログインを変更しようとしているときにエラーが発生しました。別の列にLaravelの上書きユーザー名が機能しない

タイトルには「メール」ではなく別の列を使用してログインしようとしています。なぜなら、各ユーザーに対して3つのメールがあるからです。ですから、最初はユーザー名の取得元を変更するだけです。私はすでに以下のことをしていました。

私はこのように別のモデルに耳を傾けるconfig/auth.phpファイルに編集:私のLoginController.phpファイルで

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

もが、私はこれで、関数名をオーバーライドします。

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

これは与えるものではありません。私には何らかのエラーがありますが、データベースにある資格情報でログインしようとするとリダイレクトされません。誰でも簡単な答えを知っていますか?ありがとうございました!

EDIT:

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

ok @Hoffie、ゲストは 'Authenticatable'クラスを拡張していますか? – GiuServ

答えて

0

私を私を信頼:ここ

が私のゲストテーブルのスキーマです LoginControllerのloginメソッドを次のスニペットで上書きして、私の問題を解決しました。私はそれが本当に良い習慣ではないことを知っていますが、誰かがより良い方法を知っているなら、それを分けてください。

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

関連する問題