Laravel验证错误在我看来随机出现

时间:2015-08-17 05:10:44

标签: validation laravel view controller

当我提交表单时,验证工作是随机的,我的意思是它有时会显示,有时候不会,我发现验证对象是由控制器返回的,但它总是在我的视图中循环。 这是我的代码:

from __future__ import print_function

随机显示:

  @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>

2 个答案:

答案 0 :(得分: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

谢谢:)

答案 1 :(得分:0)

最后我解决了这个问题,这是与ajax的冲突