From 35f2ebc761f2c0deeb5cff958b1c587be14ed648 Mon Sep 17 00:00:00 2001 From: merdan Date: Wed, 21 Dec 2022 19:48:37 +0500 Subject: [PATCH] cache responces achyklar --- .../Sarga/API/Http/Controllers/Brands.php | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/packages/Sarga/API/Http/Controllers/Brands.php b/packages/Sarga/API/Http/Controllers/Brands.php index e5420ce7f..671d2d109 100644 --- a/packages/Sarga/API/Http/Controllers/Brands.php +++ b/packages/Sarga/API/Http/Controllers/Brands.php @@ -3,7 +3,6 @@ namespace Sarga\API\Http\Controllers; use Illuminate\Http\Request; -use Illuminate\Support\Facades\Log; use Sarga\API\Http\Resources\Catalog\Brand; use Sarga\Brand\Repositories\BrandRepository; @@ -53,33 +52,35 @@ class Brands extends \Webkul\RestApi\Http\Controllers\V1\Shop\ResourceController $query = $query->join('menu_brands','brands.id','=','menu_brands.brand_id') ->where('menu_brands.menu_id', $menu); } - elseif($category = $request->input('category')) - { - $query = $query->join('category_brands','brands.id','=','category_brands.brand_id') - ->where('category_brands.category_id',$category); - } - if($key = $request->input('search')){ - $query = $query->where('name','like', '%'.$key.'%'); - } + $query->whereHas('flats', function($q){ + $q->where('status',1); + + if(request()->has('category')) + { + $q->whereIn('product_id',function ($q) { + $q->select('product_categories.product_id')->from('product_categories') + ->where('product_categories.category_id',request()->get('category')); + }); + } + + if($key = request()->input('search')){ + $q->where('name','like', '%'.$key.'%'); + } + }); if ($sort = $request->input('sort')) { return $query->orderBy($sort, $request->input('order') ?? 'asc'); } - - return $query->withCount('flats')->having('flats_count', '>', 1) - ->orderBy('position', 'desc') - ->orderBy('name', 'asc'); + return $query->orderBy('position', 'desc')->orderBy('name', 'asc'); }); if (is_null($request->input('pagination')) || $request->input('pagination')) { $results = $query->paginate($request->input('limit') ?? 10); - Log::info($results); } else { $results = $query->get(); - } return $this->getResourceCollection($results);