messages.blade.php
@if(count($errors) > 0)
@foreach($errors->all() as $error)
<div class="alert alert-danger">
{{$error}}
</div>
@endforeach
@endif
main.blade.php
<body class="nav-md">
<div class="container body">
@include('messages')
<div class="main_container">
AddInfocontroller
public function store(Request $request)
{
$this->validate($request,[
'fileno' => 'required|unique:AddInfoModel|max:255',
]);
输入名称= fileno 我试图离开as fileno字段 点击提交后不显示错误
如果通过ajax函数发布日期,也许这就是为什么错误没有显示或任何其他错误。如果是这样的话,如何整理出来呢?
答案 0 :(得分:0)
在控制器中进行验证并返回错误消息以查看
$validator = Validator::make($request->all(), [
'first_name' => 'required|max:255',
'last_name' => 'required|max:255',
'email' => 'required|email|max:255'
]);
if ($validator->fails()) {
return back()->withErrors($validator->errors())
->withInput($request->all());
}
答案 1 :(得分:-2)
// CONTROLLER CODES
$this->validate($request, [
'title' => 'bail|unique:posts|max:255',
'body' => 'required',
]);
//查看代码
@if($errors->has())
@foreach ($errors->all() as $error)
<div>{{ $error }}</div>
@endforeach
@endif