user() !== null; } /** * Get the validation rules that apply to the request. * * @return array|string> */ public function rules(): array { /** @var Project $project */ $project = $this->route('project'); return [ 'allowed_ticket_status_ids' => ['nullable', 'array'], 'allowed_ticket_status_ids.*' => [ 'integer', Rule::exists('ticket_statuses', 'id')->where( fn ($query) => $query->where('project_id', $project->id), ), ], ]; } /** * @return array */ public function after(): array { return [ function (Validator $validator): void { if ($validator->errors()->isNotEmpty()) { return; } /** @var TicketStatus $ticketStatus */ $ticketStatus = $this->route('ticketStatus'); $validated = $validator->validated(); $allowedTicketStatusIds = collect(Arr::get($validated, 'allowed_ticket_status_ids', [])) ->map(fn (int|string $ticketStatusId): int => (int) $ticketStatusId); if ($allowedTicketStatusIds->contains($ticketStatus->id)) { $validator->errors()->add( 'allowed_ticket_status_ids', 'A status cannot allow moves to itself.', ); } }, ]; } }