【发布时间】:2017-09-15 14:46:16
【问题描述】:
这是我的观点,我不知道为什么我的嵌套循环不起作用,请帮助我
<ul>
@foreach($users as $m)
<li> {{$m->namecategory}}
<ul>
@foreach($m->namesubcategory as $nam)
<li>{{$nam->namesubcategory}}
<ul>
@foreach($nam->namesubling as $lan)
<li>{{$lan->namesubling}}</li>
@endforeach
</ul>
</li>
@endforeach
</ul>
</li>
@endforeach
</ul>
这样的抛出错误
为 foreach() 提供的参数无效(查看
这里是使用 dd($users) 输出的
array:3 [▼
0 => {#209 ▼
+"idcategory": 1
+"namecategory": "mobile and assces"
+"created_at": null
+"updated_at": null
+"idsubcategory": 1
+"namesubcategory": "mobile"
+"idcategory_mastercategory": 1
+"idsubling": 1
+"namesubling": "iphone"
+"idsubcategory_subcategory": 1
}
1 => {#211 ▼
+"idcategory": 1
+"namecategory": "mobile and assces"
+"created_at": null
+"updated_at": null
+"idsubcategory": 2
+"namesubcategory": "mobile cover"
+"idcategory_mastercategory": 1
+"idsubling": 2
+"namesubling": "nexu cover"
+"idsubcategory_subcategory": 2
}
2 => {#212 ▼
+"idcategory": 2
+"namecategory": "elect"
+"created_at": null
+"updated_at": null
+"idsubcategory": 3
+"namesubcategory": "lap"
+"idcategory_mastercategory": 2
+"idsubling": 3
+"namesubling": "hp"
+"idsubcategory_subcategory": 3
}
]
我正在努力实现这一目标
-mobile and accessory (mastercategory)
1.mobile(subcategory)
1.iphone(subling)
2.mobile cover(subcategory)
1.iphone cover(subling)
-electronic(mastercategory)
1.laptop(subcategory)
1.hp(subling)
【问题讨论】:
-
因为
sub在$m中不存在? -
能否打印 $users 数组来检查数组是否有问题
-
欢迎来到 Stack Overflow!请使用tour,环顾四周,并通读help center,尤其是How do I ask a good question?。以上内容不足以对您有所帮助。
-
@manian 我没发现它有价值
-
var_dump $users 并提供您的问题的输出。
标签: php html laravel laravel-5.3