In my database, I have a Categories table. Categories can have parent categories, making it a recursive relationship
I also have a products table. Each product falls
Suppose your Model name is Category
Create a function on Category model
public function children() { return $this->hasMany('App\Category', 'parent_id', 'id'); }
Using above method on your controller
$categories = Category::with('children')->where('parent_id',0)->get();