filament icon indicating copy to clipboard operation
filament copied to clipboard

Add pivot attributes to Select and CheckboxList components

Open saade opened this issue 1 year ago • 1 comments

Its common to have pivot attributes on pivot tables. Currently there's no support to filling those properties when saving a Select or CheckboxList field.

The ->pivotAttributes() method

If you're using a BelongsToMany relationship and your pivot table has additional columns, you can use the pivotAttributes() method to specify the pivot attributes that should be saved:

use Filament\Forms\Components\Select;

Select::make('technologies')
    ->relationship(titleAttribute: 'name')
    ->pivotAttributes([
        'is_primary' => true,
    ])

saade avatar Feb 15 '24 20:02 saade

Just stumbled across this again, and i think this should be ->mutateRelationshipDataBeforeXUsing()?

saade avatar Feb 17 '24 00:02 saade