2017-02-02 17 views
1

私はphp artisan make:authを使用しました。ログインのためにメールアドレスをユーザ名に変更しています。 login.blade.phpで私はちょうどusernameをusernameに変更しました。ログイン後のリダイレクトは機能しませんが、登録後に正常に動作します

<div class="form-group{{ $errors->has('username') ? ' has-error' : '' }}"> 
          <label for="username" class="col-md-4 control-label">Username</label> 

          <div class="col-md-6"> 
           <input id="username" type="name" class="form-control" name="username" value="{{ old('username') }}" required autofocus> 

           @if ($errors->has('username')) 
            <span class="help-block"> 
             <strong>{{ $errors->first('username') }}</strong> 
            </span> 
           @endif 
          </div> 
         </div> 

         <div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}"> 
          <label for="password" class="col-md-4 control-label">Password</label> 

          <div class="col-md-6"> 
           <input id="password" type="password" class="form-control" name="password" required> 

           @if ($errors->has('password')) 
            <span class="help-block"> 
             <strong>{{ $errors->first('password') }}</strong> 
            </span> 
           @endif 
          </div> 
         </div> 

さて、私は間違ってcredidentalsのエラーメッセージが出ていないし、正しいcredidentalsため/homeにリダイレクトされておりません、ログインページだけで再ロードします。 また、RegisterControllerの作成機能で'username' => $data['username'],を追加しました。登録後には/ homeには正常にリダイレクトされますが、ログイン中にはリダイレクトされません。

私もlogincontrollerでこのプロパティをオーバーライドしています:Laravel 5.3でprotected $username = 'username';

+0

をテンプレートに{{ますprint_r($エラー)}}任意のメッセージを取得していますか?電子メールフィールドの検証を試みている可能性がありますが、それは存在しないため、現在そのエラーは表示されません。 –

+0

@JanWytze私は電子メールのエラーを受けましたが、このIlluminate \ Support \ ViewErrorBagオブジェクト([bags:protected] => Array([デフォルト] => Illuminate \ Support \ MessageBagオブジェクト([messages:protected )] [フォーマット:保護] =>:メッセージ))) – Steve

答えて

2

は、関数、次の上書きがありますか?

public function username() 

ベンダー/ laravel/framework/src/Illuminate/Foundation/Auth/AuthenticatesUsers.phpにあります。

変更:

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

へ:

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

また、あなたがDBにユーザ名フィールドを追加したことを確認してください。

あなたがLoginControllerはこのようなものになります。あなたが置くとき

<?php 

namespace App\Http\Controllers\Auth; 

use App\Http\Controllers\Controller; 
use Illuminate\Foundation\Auth\AuthenticatesUsers; 

class LoginController extends Controller 
{ 
    /* 
    |-------------------------------------------------------------------------- 
    | Login Controller 
    |-------------------------------------------------------------------------- 
    | 
    | This controller handles authenticating users for the application and 
    | redirecting them to your home screen. The controller uses a trait 
    | to conveniently provide its functionality to your applications. 
    | 
    */ 

    use AuthenticatesUsers; 

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

    /** 
    * Where to redirect users after login/registration. 
    * 
    * @var string 
    */ 
    protected $redirectTo = '/home'; 


    /** 
    * Create a new controller instance. 
    * 
    * @return void 
    */ 
    public function __construct() 
    { 
     $this->middleware('guest', ['except' => 'logout']); 
    } 

} 
+0

は、このプロパティ 'protected $ username = 'username';に似たこの関数ではありません; – Steve

+0

@Steveいいえhttps://github.com/laravel/framework/blob/5.3/src/Illuminate/Foundation/Auth/AuthenticateUsers.php –

+0

okをご覧ください。ありがとう。私はそれを働かせた。 – Steve

1

をあなたが例えば、LoginController.phpsendLoginResponse()メソッドをオーバーライドすることができます

protected function sendLoginResponse(Request $request) 
{ 
    $request->session()->regenerate(); 

    $this->clearLoginAttempts($request); 

    return redirect('/home'); 
} 
+0

私はそれをしましたが、まだリダイレクトされていません。私はリターンリダイレクト( '/ home');と内部認証()を使用しました。私はユーザー名に電子メールを変更しようとしています。 – Steve

+0

@ Steve私は答えを更新しました。 –

+0

これはうまくいきませんでした。 'username()'をオーバーライドしました。 – Steve

関連する問題