如何在Laravel 5中每个相关输入字段旁边显示验证错误? [英] How to Display Validation Errors Next to Each Related Input Field in Laravel 5?
本文介绍了如何在Laravel 5中每个相关输入字段旁边显示验证错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
默认解决方案很简单:
@if (count($errors) > 0)
<ul id="login-validation-errors" class="validation-errors">
@foreach ($errors->all() as $error)
<li class="validation-error-item">{{ $error }}</li>
@endforeach
</ul>
@endif
,我可以在任何地方包含 errors.blade.php
.
and I can include errors.blade.php
anywhere.
是否可以提取每个元素并将其显示在包含失败值的输入字段旁边?
Is there any way to extract each element and display it next to input field that holds the value that failed?
我认为这将要求我在每个输入旁边定义很多条件 if
语句,对吗?
I assume that would require me to define a lot of conditional if
statements next to each input, right?
如何对这个问题进行排序?你能给我例子吗?
How to sort this problem? Could you give me any examples?
谢谢.
推荐答案
您可以使用类似这样的东西:
You can use something like this :
<div class="form-group {{ $errors->has('name') ? 'has-error' : ''}}">
<label for="name" class="col-sm-3 control-label">Name: </label>
<div class="col-sm-6">
<input class="form-control" required="required" name="name" type="text" id="name">
{!! $errors->first('name', '<p class="help-block">:message</p>') !!}
</div>
</div>
这篇关于如何在Laravel 5中每个相关输入字段旁边显示验证错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文