getRepositoryInstance()->scopeQuery(function ($query) use ($request) { foreach ($request->except($this->requestException) as $input => $value) { $query = $query->whereIn($input, array_map('trim', explode(',', $value))); } if($key = $request->input('search')){ $query = $query->where('name','like', '%'.$key.'%'); } if($category = $request->input('category')){ $query = $query->rightJoin('category_brands','brands.id','=','category_brands.brand_id') ->where('category_brands.category_id',$category); } // if($brand = $request->input('brand')) // { // $query = $query->join('categories', 'category_brands.brand_id','=',$brand) // ->where('category_brands.category_id',$brand); // // ->select('categories', 'contacts.phone', 'orders.price'); // // $query = $query->join('category_brands', function (JoinClause $join) use($brand) { // // $join->on($brand, '=', 'category_brands.brand_id') // // ->where('categories.id', '=', 'category_brands.category_id'); // // }); // } // if($brand = $request->input('brand')){ // // $query = $query->rightJoin('brands','brands.id','=','category_brands.brand_id') // // ->where('categories.brand_id',$brand); // $query = $query->with('category_brands')->where('id', $brand); // } if ($sort = $request->input('sort')) { $query = $query->orderBy($sort, $request->input('order') ?? 'asc'); } else { $query = $query->orderBy('position', 'desc')->orderBy('name', 'asc'); } return $query; }); if (is_null($request->input('pagination')) || $request->input('pagination')) { $results = $query->paginate($request->input('limit') ?? 10); } else { $results = $query->get(); } return $this->getResourceCollection($results); } public function getCategory(Request $request) { $data = BrandModel::where('id', $request->input('brandId'))->with(['categories'])->first(); return $data; } }