public function attemptLogin() { $rules = array( 'email'=>'required|email','password'=>'required' ); $validator = Validator::make(Input::all(),$rules); if($validator->fails()){ return Redirect::to('login')->withErrors($validator); }; }
如果我直接在控制器中输出消息
$messages = $validator->messages(); print_R($messages->all());
return Redirect::to('login')->withErrors($validator);
视图中可用的$errors数组总是空着.
Note that when validation fails,we pass the Validator instance to the
Redirect using thewithErrors
method. This method will flash the error
messages to the session so that they are available on the next
request.
变量$errors它不是一个数组.
The
$errors
variable will be an instance of
MessageBag
.
出于某种原因,我不太喜欢@seamlss的想法.
你可以改用它.
@if(Session::has('errors')) <? $errors = Session::get('errors'); ?> <div class="alert alert-error"> <button type="button" class="close" data-dismiss="alert">×</button> <ul> <li id="form-errors" > <h3> {{ $errors->first('email') }}</h3> </li> </ul> </div> @endif
我已经使用了一些引导组件,不要混淆,你唯一需要的是带有花括号和神奇@符号的线条.
从laravel docs error-messages-and-views开始
So,it is important to note that an $errors variable will always be
available in all of your views,on every request,allowing you to
conveniently assume the $errors variable is always defined and can be
safely used.
你也可以查看this
@if( $errors->has('email') ) <div class="control-group error"> <label class="control-label" for="email">Email</label> <div class="controls"> <input type="text" id="email" placeholder="Email" name="email"> <span class="help-inline">{{ $errors->first('email') }}</span> </div> </div> @endif
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。