I am using laravel 5.7. I want to show child
data using by Parent id
I make CategoryController
. i fetch all data by parent id
show here . But i want to show all data index
page.
$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);
Controller show
<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>
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire