|string> */ public function rules(): array { return [ 'name' => ['required', 'string', 'max:255'], 'category' => ['required', Rule::enum(ServiceCategory::class)], 'type' => ['required', Rule::enum(ServiceType::class)], 'version' => ['required', 'string', function (string $attribute, mixed $value, \Closure $fail): void { if (! isset(config('keystone.services')[$this->category][$this->type]['versions'][$value])) { $fail('The selected version is invalid.'); } }], ]; } public function after(): array { return [ function ($validator): void { if ($this->category !== ServiceCategory::GATEWAY->value) { return; } $server = Server::find($this->route('server')); if ($server?->services()->where('category', ServiceCategory::GATEWAY)->exists()) { $validator->errors()->add('category', 'This server already has a gateway service.'); } }, ]; } }