Laravel 我认为验证错误随机出现
Laravel validation errors are appearing randomly in my view
当我提交我的表单时,验证是随机的,我的意思是它有时出现有时不出现,我发现验证对象是由控制器返回的,但它并不总是在我的视图中循环。
这是我的代码:
@if ($errors->any())
<ul class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</ul>
@endif
它随机显示这个:
object(Illuminate\Support\ViewErrorBag)#651 (1) { ["bags":protected]=> array(1) { ["default"]=> object(Illuminate\Support\MessageBag)#643 (2) { ["messages":protected]=> array(12) { ["province_code"]=> array(1) { [0]=> string(36) "The province code field is required." } ["district_code"]=> array(1) { [0]=> string(36) "The district code field is required." } ["training_provider"]=> array(1) { [0]=> string(40) "The training provider field is required." } ["training_center"]=> array(1) { [0]=> string(38) "The training center field is required." } ["classroom"]=> array(1) { [0]=> string(32) "The classroom field is required." } ["course_leader"]=> array(1) { [0]=> string(36) "The course leader field is required." } ["shift"]=> array(1) { [0]=> string(28) "The shift field is required." } ["start_date"]=> array(1) { [0]=> string(33) "The start date field is required." } ["end_date"]=> array(1) { [0]=> string(31) "The end date field is required." } ["start_time"]=> array(1) { [0]=> string(33) "The start time field is required." } ["end_time"]=> array(1) { [0]=> string(31) "The end time field is required." } ["course_conduct_days"]=> array(1) { [0]=> string(42) "The course conduct days field is required." } } ["format":protected]=> string(8) ":message" } } }<!DOCTYPE html>
然后出现空数组!
object(Illuminate\Support\ViewErrorBag)#652 (1) { ["bags":protected]=> array(0) { } }
如果消息包有错误则执行此操作,然后只打印它们
@if($errors->has())
<div class="alert alert-danger">
<ul>
@foreach($errors->getMessages() as $messages)
@foreach($messages as $message)
<li>{{$message}}</li>
@endforeach
@endforeach
</ul>
</div>
@endif
谢谢:)
终于解决了这个问题,是和ajax
冲突
当我提交我的表单时,验证是随机的,我的意思是它有时出现有时不出现,我发现验证对象是由控制器返回的,但它并不总是在我的视图中循环。 这是我的代码:
@if ($errors->any())
<ul class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</ul>
@endif
它随机显示这个:
object(Illuminate\Support\ViewErrorBag)#651 (1) { ["bags":protected]=> array(1) { ["default"]=> object(Illuminate\Support\MessageBag)#643 (2) { ["messages":protected]=> array(12) { ["province_code"]=> array(1) { [0]=> string(36) "The province code field is required." } ["district_code"]=> array(1) { [0]=> string(36) "The district code field is required." } ["training_provider"]=> array(1) { [0]=> string(40) "The training provider field is required." } ["training_center"]=> array(1) { [0]=> string(38) "The training center field is required." } ["classroom"]=> array(1) { [0]=> string(32) "The classroom field is required." } ["course_leader"]=> array(1) { [0]=> string(36) "The course leader field is required." } ["shift"]=> array(1) { [0]=> string(28) "The shift field is required." } ["start_date"]=> array(1) { [0]=> string(33) "The start date field is required." } ["end_date"]=> array(1) { [0]=> string(31) "The end date field is required." } ["start_time"]=> array(1) { [0]=> string(33) "The start time field is required." } ["end_time"]=> array(1) { [0]=> string(31) "The end time field is required." } ["course_conduct_days"]=> array(1) { [0]=> string(42) "The course conduct days field is required." } } ["format":protected]=> string(8) ":message" } } }<!DOCTYPE html>
然后出现空数组!
object(Illuminate\Support\ViewErrorBag)#652 (1) { ["bags":protected]=> array(0) { } }
如果消息包有错误则执行此操作,然后只打印它们
@if($errors->has())
<div class="alert alert-danger">
<ul>
@foreach($errors->getMessages() as $messages)
@foreach($messages as $message)
<li>{{$message}}</li>
@endforeach
@endforeach
</ul>
</div>
@endif
谢谢:)
终于解决了这个问题,是和ajax
冲突