我正在开展一个laravel项目,我在验证方面遇到了一些问题。 我没有看到默认的错误消息,而是看到了这样的验证要求:http://gyazo.com/681e9d8e2e176a29d90db041354f7177
这是我的代码:
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>
答案 0 :(得分:1)
验证失败时,您将返回$rules
作为错误。改变这一行:
return Redirect::to('/')->withInput()->withErrors($rules);
到此:
return Redirect::to('/')->withInput()->withErrors($validator);