我有以下验证......
<?php
protected function validator(array $data)
{
return Validator::make($data, [
'refrence_number' => 'integer',
'region' => 'integer',
'tregion' => 'integer',
'tdistrict' => 'integer',
'district' => 'integer',
'zone' => 'integer',
'tzone' => 'integer',
'ward_no' => 'integer',
'tward_no' => 'integer',
]);
}
验证工作正常,但它没有给出如下信息:
此字段应为整数。
注册页面仅重新加载。我是否还必须手动分配信息?
答案 0 :(得分:0)
您不必手动分配邮件,但您应该在视图中使用此类代码来显示错误消息:
@if ($errors->has('name'))
<span class="help-block">
<strong>{{ $errors->first('name') }}</strong>
</span>
@endif
答案 1 :(得分:0)
一个老问题,但可以帮助新朋友。 应该尝试这样的事情:
$rules = array(
"title" => "required",
"description" => "required",
);
$validator = Validator::make(Input::all(), $rules);
if($validator->fails()){
return Redirect::back()->withInput()->withErrors($validator->messages());
}
else{
// do your thing.
}
显示错误,例如:
@if($errors->any())
@foreach($errors->all() as $e1)
<div class="alert alert-danger alert-dismissible fade show" role="alert">
{{$e1}}
</div>
@endforeach
@endif