Skip to content

Commit 5f8c098

Browse files
committed
Enhance allProducts method in ProductListController to support gender filtering
This commit adds functionality to the allProducts method, allowing products to be filtered by gender. It introduces a new query condition that processes the 'gender' input, improving the product listing experience by enabling users to view products based on their selected gender.
1 parent 0fcb464 commit 5f8c098

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

app/Http/Controllers/Product/ProductListController.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ public function allProducts(Request $request){
103103
}
104104
}
105105

106+
if ($request->has('gender')) {
107+
$genderId = $request->input('gender');
108+
$query->where('product_gender', $genderId);
109+
}
110+
106111
$products = $query->paginate(6);
107112

108113
return ProductResource::collection($products);

app/Http/Resources/ProductResource.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function toArray(Request $request): array
3131
"shop_name" => $this->shop->shop_name,
3232
"shop_key" => $this->shop->shop_key,
3333
"shop_created_at" => $this->shop->created_at,
34+
"product_gender" => $this->product_gender,
3435
"shop_profile" => URL("/storage/" . $this->shop->shop_profile),
3536
"shop_id" => $this->shop->id,
3637
"review_average"=>floatval($this->reviews->avg('rating')),

0 commit comments

Comments
 (0)