我正在使用Laravel 5.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>