Support the ongoing development of Laravel.io →
Eloquent Views Blade
Last updated 2 years ago.
0

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

By:Xtreem Solution

Highly Skilled Laravel Developer

Dedicated PHP Developer

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Chetan webmechanicin Joined 26 Dec 2017

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.