I have a situation where I need to validate an identification number in two different tables (companies and units).
The company can register the units it owns, but the system cannot allow the identification code to be duplicated in the tables (companies and units).
A typical validation would look like this: Store
unique:companies,cnpj
Update
unique:companies,cnpj,{$this->company->id}
But I need to add the second table in this condition for validation, so I tried to use it as follows, but validation doesn't happen.
I tried using something like:
Store
unique:companies,cnpj|unique:units,cnpj
Someone who has been through this type of situation or has knowledge that can help me?
CodePudding user response:
Just change field name to indentification code and try this, hope it helps
'field_name' => [ 'unique:companies,cnpj,'.$this->company->id, 'unique:units,cnpj,'.$this->company->id]