Level 73
Try adding an or here
->whereRaw('(quantity - total_sold) > 0')->orWhere('created_at', '>=', Carbon::now()->subWeek())
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
$products = QueryBuilder::for(Product::class)
->allowedFilters(['name', 'user_id', AllowedFilter::scope('category')])
->allowedSorts('id')
->latest()
->whereRaw('(quantity - total_sold) > 0')
->get();
return ProductCollection::collection($products);
From the above query i would like to query only the products left for sale. It works.
NOW I WOULD LIKE TO EXTEND :
Check if the product has been added just in this week. and display it regardless if it is available or not.
Hide unavailble only if its one week old.
Try adding an or here
->whereRaw('(quantity - total_sold) > 0')->orWhere('created_at', '>=', Carbon::now()->subWeek())
Please or to participate in this conversation.