> */ public function rules(): array { return [ 'name' => [ 'required', $this->unclaimedName(), ], 'vat_id' => [ 'nullable', ], 'tax_id' => [ 'nullable', ], 'address.country_id' => [ 'required', ], ]; } /** * The name has to be free across the whole installation, with one company * excused: the one named by the request header. * * The exception is keyed on the header value rather than on a loaded model * — nothing here checks that the header names a company that exists, so a * header pointing at nothing simply excuses no row at all. */ private function unclaimedName(): Unique { return Rule::unique('companies')->ignore($this->header('company'), 'id'); } /** * The columns to write, with a slug rebuilt from the submitted name. * * Both tax identifiers are declared as nullable rules here, so unlike the * creation form they do survive into the validated payload and are written * through. The slug is derived from the raw input rather than the * validated set, which is the same string either way. */ public function getCompanyPayload() { return array_merge( Arr::only($this->validated(), self::COMPANY_FIELDS), ['slug' => Str::slug($this->name)] ); } }