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 [ 'linked_ticket_id' => [ 'required', 'integer', Rule::exists('tickets', 'id')->where('project_id', $project->id), ], 'ticket_link_type_id' => [ 'required', 'integer', Rule::exists('ticket_link_types', 'id')->where( fn ($query) => $query->where('project_id', $project->id), ), ], 'link_direction' => ['sometimes', 'required', Rule::in(['source', 'counterpart'])], ]; } /** * @return array */ public function after(): array { return [ function (Validator $validator): void { /** @var Ticket $ticket */ $ticket = $this->route('ticket'); $linkedTicketId = $this->input('linked_ticket_id'); if (is_numeric($linkedTicketId) && (int) $linkedTicketId === $ticket->id) { $validator->errors()->add('linked_ticket_id', 'A ticket cannot be linked to itself.'); } }, ]; } }