我正在使用Laravel5.7,我想展示 child
数据使用 parent id.
我创造了一个 CategoryController
我是通过 parent id
如图所示。但是,我想显示 index
第页。
<?php
$parentCat = Category::where('parent', 0)->get();
foreach ($parentCat as $parent) {
echo "<pre>";
echo $parent->category_name;
$category = Category::where('parent', $parent->id)->get();
foreach ($category as $child) {
echo "<pre>";
echo $child->category_name;
}
}
return view('fnf.category.index')->with('parent', $parentCat);
<table class="table table-striped">
<tr>
<th>Man</th>
<th><a href=""> Edit</a></th>
</tr>
<tr>
<td>Shirt</td>
<td><a href=""> Edit</a></td>
</tr>
<tr>
<td>Shirt</td>
<td><a href=""> Edit</a></td>
</tr>
<tr>
<th>Woman</th>
<th><a href=""> Edit</a></th>
</tr>
<tr>
<td>Woman Shirt</td>
<td><a href=""> Edit</a></td>
</tr>
</table>
暂无答案!
目前还没有任何答案,快来回答吧!