© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
4 replies
Xiquita

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'));
                                    }
                                };
                            }),
                    ]),
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Attach relation manager
FilamentFFilament / ❓┊help
3y ago
Relation manager attach one-to-many
FilamentFFilament / ❓┊help
3y ago
Visible for Attach Action In Relation Manager
FilamentFFilament / ❓┊help
2y ago
Relation Manager Resource with pivot - Custom Attach
FilamentFFilament / ❓┊help
3y ago