Default solution is trivial:
默认解决方案很简单:
@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
and I can include errors.blade.php anywhere.
我可以在任何地方包含errors.blade.php。
Is there any way to extract each element and display it next to input field that holds failed value?
有没有办法提取每个元素并将其显示在包含失败值的输入字段旁边?
I assume that would require to define a lot of conditional statements next to each input. Am I right? How to sort this problem? Could you give any examples?
我假设需要在每个输入旁边定义很多条件语句。我对吗?如何排序这个问题?你能举一个例子吗?
Thanks.
谢谢。
1 个解决方案
#1
12
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>
#1
12
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>