Level 51
Why not add a column??
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi. In my application I need to retrieve all the items that are 5 days to the end date.
$items = DB::table('items')
->whereRaw('DATEDIFF(end_date, NOW()) <= 5')
->get();
The method below will do the job. but the problem here is the end date is not stored on the databse.
The end date for each model is return from a method.
public function getNextDueDate($format = true)
{
$start = $this->getRepaymentCycleStartDate();
$durationSpent = $this->getDurationSpent();
$durationToAdd = $durationSpent < $this->duration ? $durationSpent + 1 : $this->duration;
$date = match($this->category->duration_period) {
'Years' => $start->addYears($durationToAdd),
'Months' => $start->addMonths($durationToAdd),
'Weeks' => $start->addWeeks($durationToAdd),
};
return $format ? $date->format('d M Y') : $date;
}
Please or to participate in this conversation.