Reputation:
controller.php
$shop['product'] = Product::with('ProductImages')->where('product_status','=',1)->where('product_drop_status','=','no')->where('language_code','=',$translate)->orderBy('product_id','desc')->get();
index.blade.php
@foreach($categories['display'] as $category)
<div class="container pt-3 mt-3 pb-3 mb-3">
<div class="row">
<h4 class="black mb-2 pb-2">{{ $category->category_name }} {{ $category->cat_id }}</h4>
<div class="swiper-container">
<div class="swiper-wrapper"> <!-- ok -->
@php $z = 1; @endphp
@foreach($shop['product'] as $product)
<!-- display products -->
@endfoeeach
i want to show category wise products.but it shows all product what should i try??
Upvotes: 0
Views: 305
Reputation: 36
You should have write query like below:
$shop['category'] = Category::->whereHas('Product', function($query) use($translate){$query->where('product_status','=',1)->where('product_drop_status','=','no')->where('language_code','=',$translate)->orderBy('product_id','desc')->with('ProductImages');})->get();
Upvotes: 0
Reputation: 66
You can use groupby because Eloquent uses the query builder internally, so you can do
GroupBy("categoryWise")
Upvotes: 1