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('project_id', $project->id), ], ]; } /** * @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.'); } }, ]; } public function linkedTicketId(): int { return (int) $this->validated('linked_ticket_id'); } public function ticketLinkTypeId(): int { return (int) $this->validated('ticket_link_type_id'); } }