In my migration, I made column
called parent_id
and it takes 0
if this category is a parent category else it takes the id
of its parent.
what I want to do is in one request I want to fetch all parent categories and inside each parent array
of its sub-category
public function index()
{
return Category::where('parent_id', '0')->each(function ($parent) {
Category::where('parent_id', $parent->id)->get();
})->get();
}