> */ public function rules(): array { /** @var Goal $goal */ $goal = $this->route('goal'); return array_merge([ 'name' => [ 'sometimes', 'string', 'max:255', ], // Whether the goal is reached when "at least" or "less than" the target time is tracked in the period 'comparison' => [ 'sometimes', 'string', Rule::enum(GoalComparison::class), ], // Target time in seconds 'target_seconds' => [ 'sometimes', 'integer', 'min:1', 'max:2147483647', ], // The recurring time frame in which the target has to be reached 'period' => [ 'sometimes', 'string', Rule::enum(GoalPeriod::class), ], // Timezone that defines the periods of the goal 'timezone' => [ 'sometimes', 'timezone:all', ], // Week start that defines weekly periods 'week_start' => [ 'sometimes', 'string', Rule::enum(Weekday::class), ], // Archived goals are hidden from the goal list by default, their progress is still calculated 'is_archived' => [ 'sometimes', 'boolean', ], // Only allowed if it matches the current type of the goal 'type' => [ function (string $attribute, mixed $value, \Closure $fail) use ($goal): void { if ($value !== $goal->type->value) { $fail('The '.$attribute.' of a goal can not be changed.'); } }, ], // Only allowed if it matches the current member of the goal 'member_id' => [ function (string $attribute, mixed $value, \Closure $fail) use ($goal): void { if ($value !== $goal->member_id) { $fail('The '.$attribute.' of a goal can not be changed.'); } }, ], ], $this->filterRules($goal->member_id === null)); } public function getName(): string { return (string) $this->input('name'); } public function getComparison(): GoalComparison { return GoalComparison::from($this->input('comparison')); } public function getTargetSeconds(): int { return (int) $this->input('target_seconds'); } public function getPeriod(): GoalPeriod { return GoalPeriod::from($this->input('period')); } public function getTimezone(): string { return (string) $this->input('timezone'); } public function getWeekStart(): Weekday { return Weekday::from($this->input('week_start')); } public function getIsArchived(): bool { return (bool) $this->input('is_archived'); } }