authorize("manageVacationLimits"); $yearPeriod = $yearPeriodRetriever->selected(); $previousYearPeriod = YearPeriod::findByYear($yearPeriod->year - 1); $limits = $yearPeriod ->vacationLimits() ->with("user.profile") ->has("user") ->get() ->sortBy(fn(VacationLimit $limit): string => "{$limit->user->profile->last_name} {$limit->user->profile->first_name}") ->values(); $limitsResource = $limits->map(fn(VacationLimit $limit): array => [ "id" => $limit->id, "user" => new UserResource($limit->user), "hasVacation" => $limit->hasVacation(), "days" => $limit->days, "remainingLastYear" => $previousYearPeriod ? $statsRetriever->getRemainingVacationDays($limit->user, $previousYearPeriod) : 0, ]); return inertia("VacationLimits", [ "limits" => $limitsResource, ]); } public function update(VacationLimitRequest $request): RedirectResponse { $this->authorize("manageVacationLimits"); $data = $request->data(); foreach ($request->vacationLimits() as $limit) { $limit->update($data[$limit->id]); } return redirect() ->back() ->with("success", __("Vacation limits have been updated.")); } }