Allowing to attach duplicate records
in a belongtomany relationship how do i change the default behavior of not allowing to attach one record twice or more, i already read the docs but its limited and i really dont understand how
Solution:Jump to solution
```
public function table(Table $table): Table
{
return $table
->recordTitle(fn (Equipment $record): string => "{$record->name}\n ({$record->equipmentbrands->name}, {$record->equipmentmodels->name}, {$record->equipmentcategories->name})")...
14 Replies
So it says right here:
https://filamentphp.com/docs/3.x/panels/resources/relation-managers#handling-duplicates
Just add the allowsDuplicates as per the docs to the relationship manager code, providing you have set a primary ID on the relationshiped table
i did the following:
didnt work and i think i do have primary ID in the pivot table
Please provide the pivot table schema?
model or migration?
table, or migration if you have a single migration for the pivot
I just source dived, do:
Instead
Yep that's good, just add on the allowDuplicates to the table definition
how so? in the migration? sorry
In the relationship manager on the $table-> declaration
Solution
boom solved, thank you sir!
Yep
I'll do a PR to the docs
Funny as Dan updated the docs 5 hours ago, so on the next Filament release it'll be deployed I suspect.
Nice π