Parent child and pivot table

Hi I have a pivot table for categories and they have parent and child relationship on the table. I wanted to use a checkbox list so a user checks children categories and it is saves to the DB. I thought of 2 ways, the relationship in filament seems to work well but it grabs all categories regardless of parent or child, so it's one big list.

I then thought maybe do each parent with just a label then have the children categories in an checkbox list, this works really well, but im not sure if when i get to saving it will work correctly or I need to do something more when saving. Thanks

                    CheckboxList::make('clothes')
    ->label('Men\'s Clothing')
    ->options([
        'shirts' => 'Shirts',
        'pants' => 'Pants',
        'jackets' => 'Jackets',
        'suits' => 'Suits',
        'shoes' => 'Shoes',
    ])
    ->bulkToggleable()
    ->extraAttributes(['class' => 'checkbox-wrapper']),

CheckboxList::make('clothes')
    ->label('Women\'s Clothing')
    ->options([
        'dresses' => 'Dresses',
        'skirts' => 'Skirts',
        'blouses' => 'Blouses',
        'pants' => 'Pants',
        'shoes' => 'Shoes',
    ])
    ->bulkToggleable()
    ->extraAttributes(['class' => 'checkbox-wrapper']),
//
Was this page helpful?