> */ public function rules(): array { $rules = [ 'name' => [ 'required', Rule::unique('companies'), 'string', ], 'currency' => [ 'required', ], ]; foreach (self::OPTIONAL_ADDRESS_FIELDS as $field) { $rules['address.'.$field] = ['nullable']; } $rules['address.country_id'] = ['required']; foreach (self::TRAILING_ADDRESS_FIELDS as $field) { $rules['address.'.$field] = ['nullable']; } return $rules; } /** * The row to insert: the allow-listed columns, with the caller stamped on * as owner and a slug derived from the name. * * The two tax identifiers carry no rule of their own, so they are never * part of the validated payload and can never be written through here. * Listed all the same, as found. */ public function getCompanyPayload() { return array_merge( Arr::only($this->validated(), self::COMPANY_FIELDS), [ 'owner_id' => $this->user()->id, 'slug' => Str::slug($this->name), ] ); } }