workspace = Workspace::findOrFail($request->workspaceId); } /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { return [ 'custom_domains' => [ 'present', 'array', function ($attribute, $value, $fail) { $errors = []; $domains = collect($value)->filter(function ($domain) { return ! empty(trim($domain)); })->each(function ($domain) use (&$errors) { if (! preg_match(self::CUSTOM_DOMAINS_REGEX, $domain)) { $errors[] = 'Invalid domain: '.$domain; } }); if (count($errors)) { $fail($errors); } $limit = $this->workspace->custom_domain_count_limit; if ($limit && $domains->count() > $limit) { $fail('You can only add '.$limit.' domain(s).'); } $this->customDomains = $domains->toArray(); }, ], ]; } protected function passedValidation() { $this->replace(['custom_domains' => $this->customDomains]); } }