在 Laravel 5.3 中针对每个字段显示错误
Display error in Laravel 5.3 against each field
我有一个带有一些验证的表单。验证后,我需要针对每个输入字段显示错误,我尝试使用 $errors->first('organizations')
来实现,但这似乎不起作用,我在屏幕上打印了 $errors->first('organizations')
。下面是我的代码片段。有人可以指出我做错了什么吗?
<div class="form-group has-feedback {{ $errors->has('organization') ? 'has-error' : '' }}">
<label class="control-label" style="{{ $errors->has('organization') ? '' : 'display:none !important;' }}" for="organization"><i class="fa fa-times-circle-o"></i> {{ $errors->has('organization') ? '$errors->first("organization")' : '' }}</label>
<select class="form-control" placeholder="Organization" id="organization" name="organization">
<option value="0" style="display: none !important;" disabled selected>Organization</option>
@foreach ($organizations as $organizations)
<option value="{{ $organizations->orgid }}">{{ $organizations->orgname }}</option>
@endforeach
</select>
</div>
所以我自己找到了答案,这似乎是处理错误消息的更好方法。留在这里留给其他新来的人吧。
<div class="form-group has-feedback {{ $errors->has('organization') ? 'has-error' : '' }}">
@if($errors->has('organization'))
<label class="control-label" for="organization"><i class="fa fa-times-circle-o"></i> {{ $errors->first('organization') }}</label>
@endif
<select class="form-control" placeholder="Organization" id="organization" name="organization">
<option value="0" style="display: none !important;" disabled selected>Organization</option>
@foreach ($organizations as $organizations)
<option value="{{ $organizations->orgid }}">{{ $organizations->orgname }}</option>
@endforeach
</select>
</div>
您可以尝试下面的代码,我在我的视图文件中使用了它
<div class="form-group @if ($errors->has('email')) has-error @endif has-feedback">
<input type="email" class="form-control" name="email" id="email" placeholder="Email" >
<span class="glyphicon glyphicon-envelope form-control-feedback"></span>
@if ($errors->has('email')) <p class="help-block">{{ $errors->first('email') }}</p> @endif
</div>
希望这会有所帮助。
你应该写这个。这将解决您的问题
<div class="form-group has-feedback {{ $errors->has('organization') ? 'has-error' : '' }}">
@if($errors->has('organization'))
<label class="control-label" for="organization"><i class="fa fa-times-circle-o"></i> {{ $errors->first('organization') }}</label>
@endif
<select class="form-control" placeholder="Organization" id="organization" name="organization">
<option value="0" style="display: none !important;" disabled selected>Organization</option>
@foreach ($organizations as $organizations)
<option value="{{ $organizations->orgid }}">{{ $organizations->orgname }}</option>
@endforeach
</select>
</div>
我有一个带有一些验证的表单。验证后,我需要针对每个输入字段显示错误,我尝试使用 $errors->first('organizations')
来实现,但这似乎不起作用,我在屏幕上打印了 $errors->first('organizations')
。下面是我的代码片段。有人可以指出我做错了什么吗?
<div class="form-group has-feedback {{ $errors->has('organization') ? 'has-error' : '' }}">
<label class="control-label" style="{{ $errors->has('organization') ? '' : 'display:none !important;' }}" for="organization"><i class="fa fa-times-circle-o"></i> {{ $errors->has('organization') ? '$errors->first("organization")' : '' }}</label>
<select class="form-control" placeholder="Organization" id="organization" name="organization">
<option value="0" style="display: none !important;" disabled selected>Organization</option>
@foreach ($organizations as $organizations)
<option value="{{ $organizations->orgid }}">{{ $organizations->orgname }}</option>
@endforeach
</select>
</div>
所以我自己找到了答案,这似乎是处理错误消息的更好方法。留在这里留给其他新来的人吧。
<div class="form-group has-feedback {{ $errors->has('organization') ? 'has-error' : '' }}">
@if($errors->has('organization'))
<label class="control-label" for="organization"><i class="fa fa-times-circle-o"></i> {{ $errors->first('organization') }}</label>
@endif
<select class="form-control" placeholder="Organization" id="organization" name="organization">
<option value="0" style="display: none !important;" disabled selected>Organization</option>
@foreach ($organizations as $organizations)
<option value="{{ $organizations->orgid }}">{{ $organizations->orgname }}</option>
@endforeach
</select>
</div>
您可以尝试下面的代码,我在我的视图文件中使用了它
<div class="form-group @if ($errors->has('email')) has-error @endif has-feedback">
<input type="email" class="form-control" name="email" id="email" placeholder="Email" >
<span class="glyphicon glyphicon-envelope form-control-feedback"></span>
@if ($errors->has('email')) <p class="help-block">{{ $errors->first('email') }}</p> @endif
</div>
希望这会有所帮助。
你应该写这个。这将解决您的问题
<div class="form-group has-feedback {{ $errors->has('organization') ? 'has-error' : '' }}">
@if($errors->has('organization'))
<label class="control-label" for="organization"><i class="fa fa-times-circle-o"></i> {{ $errors->first('organization') }}</label>
@endif
<select class="form-control" placeholder="Organization" id="organization" name="organization">
<option value="0" style="display: none !important;" disabled selected>Organization</option>
@foreach ($organizations as $organizations)
<option value="{{ $organizations->orgid }}">{{ $organizations->orgname }}</option>
@endforeach
</select>
</div>