【问题标题】:How to use a single value from foreach inside another foreach tag which is inside the same foreach如何在同一个 foreach 内的另一个 foreach 标签内使用来自 foreach 的单个值
【发布时间】:2017-05-08 12:14:09
【问题描述】:

在我的视图页面中,我使用了以下循环:

@foreach ($type as $ingtype)    
   <h4>{{$ingtype->Ing_type}}</h4> 
       @foreach (${{$ingtype->Ing_type}} as $ing)
          <input type="checkbox" name="ing[]" value="{{$ing->ing_id}}" />
          <label for="{{$ing->Ing_name}}">{{$ing->Ing_name}}</label>
       @endforeach
@endforeach

我在这里尝试做的是来自

{{$ingtype->Ing_type}}

我得到乳制品、蔬菜、肉类等的值。所以我需要 foreach 里面的那些值在

@foreach (${{$ingtype->Ing_type}} as $ing)

这一定意味着

($Dairy as $ing)

然后另一个循环给出

($Vegetable as $ing)

【问题讨论】:

  • 请提供$type的数据结构

标签: laravel laravel-5 foreach laravel-views


【解决方案1】:

可以这样直接使用

@foreach ($type as $ingtype)    
   <h4>{{$ingtype->Ing_type}}</h4> 
   @foreach ($ingtype->Ing_type as $ing)
      <input type="checkbox" name="ing[]" value="{{$ing->ing_id}}" />
      <label for="{{$ing->Ing_name}}">{{$ing->Ing_name}}</label>
   @endforeach
@endforeach

【讨论】:

  • i 抛出 foreach 中传递的参数无效的错误
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-08-14
  • 1970-01-01
  • 1970-01-01
  • 2012-05-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多