Use 𝘄𝗵𝗲𝗿𝗲𝗕𝗲𝘁𝘄𝗲𝗲𝗻 to load records between two timestamps, you can pass the fallback value using the null coalescing operator (??).
// Retrieve tasks completed within the specified time range.
Task::whereBetween('completed_at', [
$request->from ?? '2023-01-01',
$request->to ?? today()->toDateTimeString(),
]);