Unique Multiple Columns

Hi everyone, I'm using this code to validate multiple columns, but I'm not sure how to handle the exception.
No description
No description
2 Replies
Dimitry Solunsky
This solution in my job work, check please
Forms\Components\Select::make('warehouse_id')
->relationship('warehouse', 'name')
->searchable()
->preload()
->required()
->live(),

Forms\Components\Select::make('product_id')
->relationship('product', 'name')
->searchable()
->preload()
->required()
->unique(ignoreRecord: true, modifyRuleUsing: function (Unique $rule, Get $get) {
return $rule
->where('warehouse_id', $get('warehouse_id'));
}),
Forms\Components\Select::make('warehouse_id')
->relationship('warehouse', 'name')
->searchable()
->preload()
->required()
->live(),

Forms\Components\Select::make('product_id')
->relationship('product', 'name')
->searchable()
->preload()
->required()
->unique(ignoreRecord: true, modifyRuleUsing: function (Unique $rule, Get $get) {
return $rule
->where('warehouse_id', $get('warehouse_id'));
}),
Dennis Koch
Dennis Koch8mo ago
If it throws an exception your rule isn’t working. Otherwise it would return a validation exception.
Want results from more Discord servers?
Add your server