Skip to content

Commit

Permalink
feat: update category filter to support multiple category
Browse files Browse the repository at this point in the history
  • Loading branch information
ainunns authored and nisrinasalm committed Nov 28, 2024
1 parent 7008382 commit 67b74a3
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions app/Http/Controllers/TransactionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ class TransactionController extends Controller
{
public function index(Request $request)
{
$categoryId = $request->query('category_id');
$categoryIds = $request->query('category_id', []);
$startDate = $request->query('start_date');
$endDate = $request->query('end_date');

$category = Category::all();

$transaction = Transaction::with(['cart_product.product.category'])
->whereHas('cart_product.product.category', function ($query) use ($categoryId) {
if ($categoryId) {
$query->where('category_id', $categoryId);
->whereHas('cart_product.product.category', function ($query) use ($categoryIds) {
if (!empty($categoryIds)) {
$query->whereIn('category_id', $categoryIds);
}
})
->whereHas('cart_product', function ($query) {
Expand All @@ -41,7 +41,7 @@ public function index(Request $request)
return Inertia::render('Transaction/Index', [
'transaction' => $transaction,
'category' => $category,
'categoryId' => $categoryId,
'categoryIds' => $categoryIds,
'startDate' => $startDate,
'endDate' => $endDate,
]);
Expand Down

0 comments on commit 67b74a3

Please sign in to comment.