Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ntn0de's avatar

Some Assistance with the query PLEASE!!

$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.
0 likes
3 replies
Tray2's avatar
Tray2
Best Answer
Level 73

Try adding an or here

->whereRaw('(quantity - total_sold) > 0')->orWhere('created_at', '>=', Carbon::now()->subWeek())
1 like
ntn0de's avatar

@tray2 Thanks! Got too lazy to just try it before asking :D

Please or to participate in this conversation.