Morning bipin.
This is a bit rough but its something like this:
Category.php Model
public function products()
{
return $this->hasMany(Product::class);
}
public function subCategories()
{
return $this->hasMany(Category::class);
}
SubCategory.php Model
public function category()
{
return $this->belongsTo(Category::class);
}
Product.php Model
public function category()
{
return $this->belongsTo(Category::class);
}
Then in controller you get results:
$categories = Category::all();
Then in view:
@foreach($categories as $category)
// echo out category title
@foreach($category->subCategories as $subCategory)
// echo out sub category title
@foreach($subCategory->products as $product)
// echo out product title