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

tomasosho's avatar

I want to foreach notification 5days before the service date

I want to foreach notification in my view 5days before the service_date`` service_dateis set by the user and date serviced is also set by the user asdate```. How do i go about it? The code only displays notification when the service_date = today's date

$date = date("Y-m-d");
$notification = Maintenance::where('service_date', '=', $date)->get();
0 likes
6 replies
tykus's avatar
tykus
Best Answer
Level 104

We're back here again... Why does this not work for you?

$notification = Maintenance::whereBetween('service_date', [today(), today()->addDays(5)])
	->get();

What result is is producing that you can't work with?

1 like
MichalOravec's avatar
$notification = Maintenance::where('service_date', '>=', now()->subDays(5))->get();
1 like
tykus's avatar

The array was empty

Is there a record with service_date in the database within that range (today, today + 5)? What is the datatype of the service_date column

tomasosho's avatar

i got [] array, i had to run migration again. I think there was some type of error.

Please or to participate in this conversation.