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
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.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community