我在laravel 5.3中使用验证。但错误消息未显示。该怎么办?
public function store(Request $request)
{
$validator = Validator::make($request->all(), [
'name'=>'required|min:2',
'address'=>'required',
'email'=>'required',
'contact_number'=>'required',
'date_of_birth'=>'required',
'company_name'=>'required',
'country'=>'required',
'city'=>'required',
'fax'=>'required',
'telephone'=>'required',
'picture_upload'=>'required',
]);
}
在视图中
@foreach ($errors->all() as $error)
<li>{!! $error !!}</li>
@endforeach
答案 0 :(得分:0)
我通常使用FromRequests进行验证,但我非常确定验证器使用Request
对象,但是您将它传递给数组$request->all()
,只需将其更改为:{{1} }
答案 1 :(得分:0)
这样做: 在控制器
$this->validate($request, [
'name'=>'required|min:2',
'address'=>'required',
'email'=>'required',
'contact_number'=>'required',
'date_of_birth'=>'required',
'company_name'=>'required',
'country'=>'required',
'city'=>'required',
'fax'=>'required',
'telephone'=>'required',
'picture_upload'=>'required',
]);
在视图中
@if (count($errors) > 0)
<div class="alert alert-danger alert-dismissible fade in" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span>
</button>
<strong>OOPS! You might have missed to fill some required fields. Please check the errors. <strong>
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif