I'm trying to validate 'parent_code' attr regarding 'level' field value
Here is what i'm trying to achieve :
'parent_code' is only required when 'level' is != 0 (This part works fine)
and when it's set, it must also exists in table 'products' ('product_code' : the column name that will be used)
My current code (doesn't work properly)
Product resource class
public function fields(Request $request) {
return [
ID::make()->sortable(),
Text::make('Product code', 'product_code')
->rules('required')
->creationRules('unique:products,product_code')
->updateRules('unique:products,product_code,{{resourceId}}')->hideFromIndex(),
Text::make('Product short name', 'product_short_name')->onlyOnForms(),
Textarea::make('Product name', 'product_name')
->rules('required')
->sortable()
->onlyOnForms(),
Text::make('Parent code', 'parent_code')
->rules(['required_if:level,2,4,6', 'exists:products,product_code'])
->hideFromIndex(),
Select::make('Level', 'level')->options([
'0' => 'Sector level',
'2' => 'H2',
'4' => 'H4',
'6' => 'H6',
])->rules('required')->sortable(),
];
}
Create Product Form
Thank you for your help.

existsrule only if therequired ifis satisfied?