While using the whereBetween()
to load records between two timestamps, you can pass the fallback value using the null coalescing operator (??).
// Load tasks completed between two timestampsTask::whereBetween('completed_at', [ $request->from ?? '2023-01-01', $request->to ?? today()->toDateTimeString(),]);
Tip given by @LaraShout