F
Filament10mo ago
cvc

Check for uniqueness according to column title for grouped records

Hi I am trying to check for uniqueness of a Status Title - based on the model type. This is my code (but its probably junk!!)
Forms\Components\TextInput::make('title')
->autofocus()
->required()
->unique(Status::class, 'title',
ignoreRecord: true,
modifyRuleUsing: function (Unique $rule) {
//we want ensure that we have unique titles per model_type when editing the record
$rule->where('model_type', request()->input('record.model_type'));

return $rule;
})
->placeholder(__('Title')),
Forms\Components\TextInput::make('title')
->autofocus()
->required()
->unique(Status::class, 'title',
ignoreRecord: true,
modifyRuleUsing: function (Unique $rule) {
//we want ensure that we have unique titles per model_type when editing the record
$rule->where('model_type', request()->input('record.model_type'));

return $rule;
})
->placeholder(__('Title')),
Basically have 2 columns the model_type and the Title, so want to ensure that title is unique for each model_type (i added the ignoreRecord to allow editing of the title.
0 Replies
No replies yetBe the first to reply to this messageJoin