I'm editing a Laravel 4.3 site and I have a db table called categories which has the following fields:
id parent_id name I'm trying to output a list in my view of categories, and their subcategories:
Category Another Category Subcat Subcat Subcat I'm not really sure of the best way of achieving this and hoping someone can help point me in the right direction :-)
this is my controller
public function store(Request $request) {
$this->validate($request, [
'name' =>'required'
]);
$category= new Category;
$category= Category::with('children')->whereNull('parent_id')->get();
$category->name =$request->name;
$category->save();}
Category::with('children')->whereNull('parent_id')->get(), because if the parent it null how the children will be there? - Sethu