subDays($request->integer('days', 365))->startOfDay(); $entries = $request->user() ->weightEntries() ->where('measured_at', '>=', $from) ->latest('measured_at') ->get(); return WeightEntryResource::collection($entries); } /** * Store a newly created resource in storage. */ public function store(StoreWeightEntryRequest $request): WeightEntryResource { $entry = $request->user()->weightEntries()->create([ 'weight_kg' => $request->validated('weightKg'), 'measured_at' => CarbonImmutable::parse($request->validated('measuredAt') ?? now()), ]); return new WeightEntryResource($entry); } /** * Remove the specified resource from storage. */ public function destroy(Request $request, WeightEntry $weightEntry): Response { abort_unless($weightEntry->user_id === $request->user()->getKey(), 404); $weightEntry->delete(); return response()->noContent(); } }