Attach Relation Manager
Hello friends, I have a question, how is it that in the attach of a relation manager I attach the same record already registered?
Tables\Actions\AttachAction::make()
->recordSelect(
fn (Select $select) => $select->noSearchResultsMessage(__('equipment.equipment_resource.search_field')),
)
->allowDuplicates()
->color('success')
->preloadRecordSelect()
->form(fn (AttachAction $action): array => [
$action->getRecordSelect(),
Forms\Components\TextInput::make('serial_number')
->numeric()
->minValue(1)
->label(__('construction-equipment.construction_equipment_resource.serial_number'))
->unique(ignoreRecord: true)
->required()
->maxLength(255)
->rule(static function (Forms\Get $get, Forms\Components\Component $component): Closure {
return static function (string $attribute, $value, Closure $fail) use ($get, $component) {
$existingRecord = DB::table('construction_has_equipment')
->where('serial_number', $value)
->exists();
if ($existingRecord) {
$fail(__('construction-equipment.construction_equipment_resource.error'));
}
};
}),
]),Tables\Actions\AttachAction::make()
->recordSelect(
fn (Select $select) => $select->noSearchResultsMessage(__('equipment.equipment_resource.search_field')),
)
->allowDuplicates()
->color('success')
->preloadRecordSelect()
->form(fn (AttachAction $action): array => [
$action->getRecordSelect(),
Forms\Components\TextInput::make('serial_number')
->numeric()
->minValue(1)
->label(__('construction-equipment.construction_equipment_resource.serial_number'))
->unique(ignoreRecord: true)
->required()
->maxLength(255)
->rule(static function (Forms\Get $get, Forms\Components\Component $component): Closure {
return static function (string $attribute, $value, Closure $fail) use ($get, $component) {
$existingRecord = DB::table('construction_has_equipment')
->where('serial_number', $value)
->exists();
if ($existingRecord) {
$fail(__('construction-equipment.construction_equipment_resource.error'));
}
};
}),
]),