【发布时间】:2018-06-14 14:16:46
【问题描述】:
在数组数组的迭代过程中出现此错误:
为 foreach() 提供的参数无效(查看: C:\xampp\htdocs\smartcalws\resources\views\location\index.blade.php
在视图中的代码下方:
@foreach($Nations as $e)
<tr>
<th scope="row">{{$e->id}}</th>
<td>{{$e->name}}</td>
@foreach($e->districts as $d)
<td>{{$d->name}}</td>
@endforeach
@endforeach
谁能知道原因?
在控制器中,如果我执行 foreach,所有 echo 都可以正常工作:
foreach($Nations as $e){
foreach($e->districts as $d){
echo $d->name;
}
}
所有国家都有地区。 echo 打印所有区域。我认为问题出在刀片页面...
return view('Nations.index',compact('Nations',$Nations));
【问题讨论】:
-
显示设置
$Nations值的控制器代码。$e中也不能有districts,也要检查一下。 -
$Nation和districts是什么关系?就像@u_mulder 说的,可能没有返回的地区 -
Nations 具有名称、其他信息和地区列表等属性。国家和地区都是一个集合
-
你是如何将该值传递给刀片的?