published() ->visible(); if (request('category')) { $query->whereHas('categories', function ($q) { $q->where('slug', request('category')); }); } if (request('featured')) { $query->featured(); } if (request('in_stock')) { $query->inStock(); } $products = $query->with(['categories']) ->paginate($perPage); return response()->json($products); } public function show(string $slug): JsonResponse { $productModel = config('shop.models.product'); $product = $productModel::query() ->published() ->visible() ->where('slug', $slug) ->with(['categories', 'images', 'children', 'attributes']) ->firstOrFail(); return response()->json([ 'data' => array_merge( $product->toArray(), [ 'current_price' => $product->getCurrentPrice(), 'on_sale' => $product->isOnSale(), 'average_rating' => $product->getAverageRating(), ] ), ]); } }