diff --git a/app/Http/Controllers/Api/ProductController.php b/app/Http/Controllers/Api/ProductController.php index 6694d24..9ab2837 100644 --- a/app/Http/Controllers/Api/ProductController.php +++ b/app/Http/Controllers/Api/ProductController.php @@ -28,7 +28,7 @@ class ProductController extends Controller * required=false, * @OA\Schema( * type="string", - * enum={"new", "old", "most_view", "less_view", "most_buy", "less_buy"} + * enum={"new", "old", "most_view", "less_view", "most_buy", "less_buy","cheap","expensive"} * ) * ), * @OA\Parameter( @@ -100,6 +100,10 @@ class ProductController extends Controller $product = $product->orderByDesc('sell'); if ($request['sort'] === 'less_buy') $product = $product->orderBy('sell'); + if ($request['sort'] === 'cheap') + $product = $product->orderBy('price'); + if ($request['sort'] === 'expensive') + $product = $product->orderByDesc('price'); } if (isset($request['category']) && !is_null($request['category'])) $product = $product->where('category_id', Category::firstWhere('slug', $request['category'])->id); diff --git a/storage/api-docs/api-docs.json b/storage/api-docs/api-docs.json index 981dde8..c1cc7b0 100644 --- a/storage/api-docs/api-docs.json +++ b/storage/api-docs/api-docs.json @@ -107,7 +107,9 @@ "most_view", "less_view", "most_buy", - "less_buy" + "less_buy", + "cheap", + "expensive" ] } },