2014-10-27 116 views
0

我正在開發一個laravel項目,並且在驗證過程中遇到了一些問題。 默認的錯誤消息不出現,而不是我能看到這樣的驗證要求:http://gyazo.com/681e9d8e2e176a29d90db041354f7177Laravel驗證未顯示默認錯誤消息

這是我的代碼:

routes.php文件(我把所有的代碼在這裏現在)

Route::filter('checkLogin', function() 
{ 


    if(Input::GET('email') != ""){ //register 


     $rules = 
     array(
      'username' => 'required|max:64|min:3|unique:users', 
      'password' => 'required|max:64|min:6', 
      'fname' => 'required|max:255|alpha', 
      'lname' => 'required|max:255|alpha', 

      'email' => 'required|max:255|email', 
      'phone' => 'max:24|min:9', 
      'zip' => 'required', 
      'street' => 'required|max:255|alpha', 
      'housenumber' => 'required|max:6|numeric', 
      'country' => 'required', 
      'avatar' => 'max:32' 
     ); 


    $validator = Validator::make(Input::all(), $rules); 
    if($validator->fails()) { 
     return Redirect::to('/')->withInput()->withErrors($rules); 
    } 
} 

});

這是怎麼從視圖代碼:

    <div class="fields"> 
         <div class="field"> 
          <i class="fa fa-user"></i> 
          {{ Form::text('username', null, ['placeholder' => 'Username', 'tabindex' => 1]) }} 
          {{ $errors->first('username') }} 

         </div> 
         <div class="field"> 
          <i class="fa fa-lock"></i> 
          {{ Form::password('password', ['placeholder' => 'Password', 'tabindex' => 2]) }} 
          <a href="forgot" class="fa fa-question-circle login" title="Forgot Password?"></a> 
          {{ $errors->first('password') }} 
         </div> 
        </div> 

回答

1

驗證失敗時,你正在返回你的$rules的錯誤。改變這一行:

return Redirect::to('/')->withInput()->withErrors($rules); 

這樣:

return Redirect::to('/')->withInput()->withErrors($validator); 
+0

哦,是ofcourse。非常感謝! – jasper 2014-10-27 02:24:18