FilamentF
Filamentβ€’14mo agoβ€’
4 replies
TheRealTeeHill

Displaying CheckboxList across multiple Fieldsets using relationship

I have Fleets, Vessels and RemoteScripts.

A RemoteScript belongs to many Vessels via a pivot table, a Vessel belongs to a Fleet.

When I do
CheckboxList::make('vessels')->('vessels', 'name')
it works and displays all the Vessels in the list, checking and unchecking boxes is reflected in the pivot table. But I would like to display each CheckboxList in a Fieldset for each Fleet.

Between Google and GPT I have got this

...$fleets->map(function ($fleet) {
    return Fieldset::make($fleet->name)
        ->schema([
            CheckboxList::make("vessels_{$fleet->id}")
                ->options($fleet->vessels->pluck('name', 'id'))
                ->label(''),
        ])
        ->columnSpan(1);
})->toArray(),


This lists each CheckboxList in a Fieldset for each Fleet but the pivot table is not updating nor are the records in the pivot table reflected in the checkboxes.

I have seen
 ->saveRelationshipsUsing()
, is this something that will help resolve this issue?

Cheers, Tee
Solution
@Dennis Koch I managed to fudge something together... I won't post the code cos its a mess but if someone did have the same problem I am happy to share it πŸ™‚ I ended up using afterStateUpdated, default and afterStateHydrated to get it going how I wanted... probs a better way but for now I just needed the functionality πŸ‘
Was this page helpful?