Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 1 year ago.
0

Did you set already the relationship between them, in their models?

What i would suggest is :

Controller


$shops = Shop::find($shopID);

$products = Shop::find($shopID)->product;

return in your view with($shops and $products)

now the loop in the view


@foreach($shops->categories as $shop)
 
{{ $shop->category_name }}  //or whatever you want to get

@endforeach

@foreach($products as $product)

{{ $product->product_name }}

@endforeach

Last updated 1 year ago.
0

Yes i set the relationships.

Your idea is going in the right way. But what i need to show is under each category the products, that belong to the category

like:

@foreach($shop->category as $category)

{{ $category->name }}

@foreach($category->products as $products)

{{ $product->name }}

@endforeach

@endforeach

This i do already. But instead of only the product for the shop and the category i get all products to the category, doesn't matter which store it is.

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

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.