Hmm why are you using the closure? You should be able to chain where clauses.
edit: are they in that format? I believe the format should match what's in the database
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have following code
$date = Carbon::today()->format('d-m-Y');
Want to retrieve data if user_id matches and the $date is between start_date and end_date
Leave::where('user_id', $user->id)
->where(function ($query) use ($date) {
$query->where('start_date', '<=', $date)
->where('end_date', '>=', $date);
})->get();
The above query does not return any data.
Note: the value of $date => '09-02-2022', start_date => '2022-02-08 00:00:00' and end_date => '2022-02-09 10:30:00'
Use 'Y-m-d' to format your date. If it's still not working, inspect the query that's being generated and post here.
Please or to participate in this conversation.