Are you sure that check is passing; does this expression request('date') === 'twoweeks' evaluate true?
Also, if you are filtering by a date; then whereDate is probably more appropriate
$q->whereDate('closingDate', '>=', today()->subDays(30));
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi All, I am trying to return events that are within the last 30 days. I am using the code
public function fetch(Request $request)
{
return Event::whereIn('status',['p', 'e'])
->with('user','clicks','category', 'location', 'remotelocations', 'organizer', 'shows', 'curatedCheck')
->when(request('date') === 'published', function ($q) {
$q->orderByDesc('published_at');
})
->when(request('date') === 'updated', function ($q) {
$q->orderByDesc('updated_at');
})
->when(request('date') === 'twoweeks', function ($q) {
$q->where(
'closingDate','>=', Carbon::now()->subDays(30)->toDateTimeString()
);
})
->paginate(15);
}
However when I make request(date) = to twoweeks nothing is filtered. I am loading Carbon into my controller.
Please or to participate in this conversation.