validated(); $workoutSessionsQuery = $request->user()->workouts(); if (isset($validated['date'])) { $referenceDate = CarbonImmutable::createFromFormat('!Y-m-d', $validated['date']); $workoutSessionsQuery->whereBetween('started_at', [ $referenceDate->startOfDay(), $referenceDate->endOfDay(), ]); } $workoutSessions = $workoutSessionsQuery ->latest('started_at') ->paginate($request->integer('per_page', 15)) ->withQueryString(); return WorkoutSessionsResource::collection($workoutSessions); } public function store(WorkoutSessionsRequest $request): JsonResponse { $workoutSession = $request->user() ->workouts() ->create($request->validated()); return (new WorkoutSessionsResource($workoutSession)) ->response() ->setStatusCode(201); } }