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

phpMick's avatar

Eloquent date range and multiple where

How can I do a SELECT where a date is < three weeks old and also matches an ID?

Bit like this:

$availableProductID = AvailableProduct::where('product_id', '=', $productID, 'made_available', '<', $weeksAvailableFor )->get();

0 likes
7 replies
d3xt3r's avatar

You can chain your wheres, like where(condition1 ...) -> where(condition2) -> get();

Also, check out whereRaw if you need to do some modification on the fields.

phpMick's avatar

Got the chaining working now.

Now I want to do WHERE (made_available + 3 weeks) < today

Can I do that in one hit?

d3xt3r's avatar
->where('made_available ', '<', Carbon::now()->addWeeks(-3))
willvincent's avatar
Level 54
$results = AvailableProduct::where('product_id', '=', $productID)
                             ->where('made_available', '<', Carbon::now()->subWeeks(3))
                             ->get();
1 like
phpMick's avatar

Thanks, was having a mental block with that!

Please or to participate in this conversation.