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(),
...$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 πŸ‘
Jump to solution
2 Replies
Dennis Koch
Dennis Kochβ€’2w ago
Currently it works because you use ->relationship() right? If you want to split your CheckboxLists up, you need to save the data yourself. Best to just overwrite the save() method of that page and combine them there
Solution
TheRealTeeHill
TheRealTeeHillβ€’2w ago
@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 πŸ‘

Did you find this page helpful?