I am using Laravel 5.7 and I want to show child
data using parent id.
I created a CategoryController
and I am fetching the data by parent id
shown here. However, I want to show all the data in the index
page.
<?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>