Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel 如何中断第二个foreach循环_Laravel_Laravel 5.6 - Fatal编程技术网

Laravel 如何中断第二个foreach循环

Laravel 如何中断第二个foreach循环,laravel,laravel-5.6,Laravel,Laravel 5.6,实际上,在这段代码中,我试图显示表单标签和表单输入字段来自数据库 在第一个foreach循环中,包含一个标签 其次,foreach包含输入字段数据 如果第二个foreach没有数据,两个foreach都不工作,我该怎么办 @section('body') <!--{{session('uid')}} --> <div class="col-sm-12"> <!-- Wizard container

实际上,在这段代码中,我试图显示
表单标签
表单输入
字段来自数据库

  • 在第一个foreach循环中,包含一个
    标签
  • 其次,foreach包含
    输入
    字段数据
如果第二个foreach没有数据,两个foreach都不工作,我该怎么办

@section('body') 

     <!--{{session('uid')}} -->

      <div class="col-sm-12">
        <!--      Wizard container        -->
             <div class="wizard-container">
                <div class="card wizard-card" data-color="red" id="wizard">
                   <form action="{{URL::to('faculty/submitreport')}}" method="post" name="reportform">
                       <!--        You can switch " data-color="blue" "  with one of the next bright colors: "green", "orange", "red", "purple"             -->
                        {{ csrf_field()}}
                        <div class="wizard-header">
                           <h3 class="wizard-title">
                               Monthly Progress Report
                           </h3>
                           <h5>This information will let us know more about you.</h5>
                         </div>

                    @foreach($fetchform as $data)
                      @foreach($fetchans as $ans)

                        @if(is_null($ans)){
                           @break

                           <div class="wizard-navigation">
                              <ul>
                                <li><a href="#details" data-toggle="tab">{{$data->f_title}}</a></li>
                              </ul>
                           </div>

                           <div class="tab-content">
                              <div class="tab-pane" id="details">
                                 <div class="row">                  
                                    <div class="col-lg-12">
                                       @if(is_null($data->f1))
                                       @else

                                        <div class="form-group label-floating">                                    <label class="control-label">{{$data->f1}}</label>
                                             <input name="f1" type="text" class="form-control"value='{{$ans->f1}}'></input>     
                                        </div>
                                       @endif                                       

                            @if(is_null($data->f2))
                            @else
                                <div class="form-group label-floating">
                                    <label class="control-label">{{$data->f2}}</label>
                                    <input name="f2" type="text" class="form-control" value='{{$ans->f2}}'></input>     
                                </div>
                            @endif          

                            @if(is_null($data->f3))
                            @else
                                <div class="form-group label-floating">
                                    <label class="control-label">{{$data->f3}}</label>
                                    <input name="f3" type="text" class="form-control" value='{{$ans->f3}}'></input>     
                                </div>
                            @endif          

                            @if(is_null($data->f4))
                            @else
                              <div class="form-group label-floating">
                                    <label class="control-label">{{$data->f4}}</label>
                                    <input name="f4" type="text" class="form-control" value='{{$ans->f4}}'></input>     
                               </div>
                            @endif          

                            @if(is_null($data->f5))
                            @else
                               <div class="form-group label-floating">
                                    <label class="control-label">{{$data->f5}}</label>
                                    <input name="f5" type="text" class="form-control" value='{{$ans->f5}}'></input>     
                               </div>
                            @endif          

                            @if(is_null($data->f6))
                            @else
                               <div class="form-group label-floating">
                                    <label class="control-label">{{$data->f6}}</label>
                                    <input name="f6" type="text" class="form-control" value='{{$ans->f6}}'></input>     
                               </div>
                            @endif          

                            @if(is_null($data->f7))
                            @else
                               <div class="form-group label-floating">
                                    <label class="control-label">{{$data->f7}}</label>
                                    <input name="f7" type="text" class="form-control" value='{{$ans->f7}}'></input>     
                               </div>
                            @endif          

                            @if(is_null($data->f8))
                            @else
                               <div class="form-group label-floating">
                                    <label class="control-label">{{$data->f8}}</label>
                                    <input name="f8" type="text" class="form-control" value='{{$ans->f8}}'></input>     
                               </div>
                            @endif          

                            @if(is_null($data->f9))
                            @else
                               <div class="form-group label-floating">
                                <b> <label class="control-label">{{$data->f9}}</label></b>
                                    <input name="f9" type="text" class="form-control" value='{{$ans->f9}}'></input>     
                               </div>
                           @endif           

                           @if(is_null($data->f10))
                           @else
                               <div class="form-group label-floating">
                                 <b>    <label class="control-label">{{$data->f10}}</label></b>
                                    <input name="f10" type="text" class="form-control" value='{{$ans->f10}}'></input>       
                               </div>
                           @endif           

                           @if(is_null($data->f11))
                           @else
                               <div class="form-group label-floating">
                                  <b>       <label class="control-label">{{$data->f11}}</label> </b>
                                    <input name="f11" type="text" class="form-control" value='{{$ans->f11}}'></input>       
                               </div>
                           @endif           

                           @if(is_null($data->f12))
                           @else
                              <div class="form-group label-floating">
                                 <b>    <label class="control-label">{{$data->f12}}</label></b>
                                    <input name="f12" type="text" class="form-control" value='{{$ans->f12}}'></input>       
                              </div>
                           @endif

                           <input type='hidden' name="f_id" value='{{$data->f_id}}'>
                           <input type='hidden' name="u_id" value='{{session()->get("uid")}}'>
                           <input type='hidden' name="f_status" id="f_status" />
                    </div>
                   }
                 @endif                                 
              @endforeach
            @endforeach  

         </div>
        </div>
       </div>       
     </div>

     <div class="wizard-footer">
          <div class="pull-right">
              <input type='submit' class='btn btn-next btn-fill btn-danger btn-wd-lg' name='save' value='Save' />
               <input type='button' class='btn btn-finish btn-fill btn-danger btn-wd-lg' onclick="myFunction()" name='Submit' value='submit' />
          </div>
          <div class="clearfix"></div>
        </div>
      </form>
    </div>
 </div> <!-- wizard container -->
</div>

<script>
function myFunction() {
    var txt;
    var r = confirm("Really Do You Want To Finally Submit a Form \n After Submitting You Can't Update Anything into It.");
    if (r == true) {
        document.getElementById("f_status").value = '1';
        reportform.submit();
    } else {

    }

}
</script>
@节(“正文”)
{{csrf_field()}}
每月进展报告
这些信息会让我们更多地了解你。
@foreach($fetchformas$data)
@foreach($fetchans作为$ans)
@如果(为空($ans)){
@中断
@如果(为空($data->f1)) @否则 {{$data->f1} @恩迪夫 @如果(为空($data->f2)) @否则 {{$data->f2} @恩迪夫 @如果(为空($data->f3)) @否则 {{$data->f3} @恩迪夫 @如果(为空($data->f4)) @否则 {{$data->f4} @恩迪夫 @如果(为空($data->f5)) @否则 {{$data->f5} @恩迪夫 @如果(为空($data->f6)) @否则 {{$data->f6} @恩迪夫 @如果(为空($data->f7)) @否则 {{$data->f7} @恩迪夫 @如果(为空($data->f8)) @否则 {{$data->f8} @恩迪夫 @如果(为空($data->f9)) @否则 {{$data->f9} @恩迪夫 @如果(为空($data->f10)) @否则 {{$data->f10} @恩迪夫 @如果(为空($data->f11)) @否则 {{$data->f11} @恩迪夫 @如果(为空($data->f12)) @否则 {{$data->f12} @恩迪夫 } @恩迪夫 @endforeach @endforeach 函数myFunction(){ var-txt; var r=confirm(“确实要最终提交表单吗?\n在提交表单后,您不能将任何内容更新到表单中。”); 如果(r==true){ document.getElementById(“f_状态”)。值='1'; reportform.submit(); }否则{ } }

@endsection

通过读取代码,您似乎试图用
$data
变量的值填充
标签
元素,用
$ans
变量的值填充
输入
字段。现在编写代码时,您正在循环使用
$fetchform
中的所有项目,每次循环时,您都会遍历
$fetchans
的所有值。所以,如果你有3个表单项和3个答案,你实际上会运行9个循环
    //loop through all items in $fetchform
    @for ($i = 0; $i < count($fetchform); $i++)
        //php tags needed in blade to set the variables
        @php 
            $data = $fetchform[$i]; //get the form data
            $ans = $fetchans[$i]; //get the corresponding form answer
        @endphp

        //it might be more appropriate to check these for 'empty' instead of null
        //that all depends on your code
        @if(!is_null($data) || !is_null($ans))

            //make sure object has the 'f1' key and value is not null
            @if(array_key_exists('f1', $data) && !is_null($data->f1))
                <div class="form-group label-floating">
                    <label class="control-label">{{ $data->f2 }}</label>
                    <input name="f2" type="text" class="form-control" value='{{ $ans->f2 }}' />     
                </div>
            @endif
        @endif
    @endfor