這裏是我的看法,我不知道爲什麼我的嵌套德路不能正常工作,請幫助我爲什麼嵌套循環中laravel不工作
<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($用戶)
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
}
]
和IM嘗試實現這一
-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數組來檢查數組中是否存在問題 – manian
歡迎使用Stack Overflow!請[參觀],看看周圍,並通讀[幫助],尤其是[*我如何問一個好問題?](/幫助/如何問)沒有足夠的上面的細節能夠有效地幫助你。 –