If you need to retrieve records between two timestamps, you can use
whereBetween method with a from and to date. You can also to provide a fallback with the null coalescing operator (which was implemented in PHP since version 7+).
Post::whereBetween('published_at', [ $request->from ?? '1980-01-01', $request->to ?? today()->toDateTimeString(), ])->get();