`->unique()` rule inside relationship instead of whole table

Hey guys, I have this url /{clientSlug}/{productSlug} On ClientResource, I have a ->unique(ignoreRecord: true) on the slug field and this works fine. Now I want to be able to create multiple product with the same productSlug unless they have the same parent (client). I found ->unique(modifyRuleUsing: function (Unique $rule, $record) but I'm not sure how to implement this. Basically, I want to be able to do /client-1/product-1 and /client-2/product-1. But I don't want to be able to create multiple product-1 on client-1
Solution:
I think I got it: ```php Forms\Components\Select::make('client_id') ->relationship('client', 'name') ->required()...
Jump to solution
1 Reply
Solution
mrleblanc101
mrleblanc1015mo ago
I think I got it:
Forms\Components\Select::make('client_id')
->relationship('client', 'name')
->required()
->default(request()->query('ownerRecord')),
Forms\Components\TextInput::make('slug')
->unique(
ignoreRecord: true,
modifyRuleUsing: function (Unique $rule, $get) {
return $rule->where('client_id', $get('client_id'));
})
->default('site-web'),
Forms\Components\Select::make('client_id')
->relationship('client', 'name')
->required()
->default(request()->query('ownerRecord')),
Forms\Components\TextInput::make('slug')
->unique(
ignoreRecord: true,
modifyRuleUsing: function (Unique $rule, $get) {
return $rule->where('client_id', $get('client_id'));
})
->default('site-web'),
Want results from more Discord servers?
Add your server