How to preselect a CheckboxList

Hey, how is it possible to preselect some values on a CheckboxList I already tried the ->default([{"10":"Test"}]) but this does not work. This is the complete code
Section::make('Attribute')
->schema(
self::getAttributeData(Resort::class)
->map(fn($attributes, $group) =>
CheckboxList::make($group)
->statePath('attributes')
->options(fn () => $attributes)
->default(fn (Resort $record) => $record->attributes()->pluck('name', 'id'))
)->toArray()
)
->columns(3)
Section::make('Attribute')
->schema(
self::getAttributeData(Resort::class)
->map(fn($attributes, $group) =>
CheckboxList::make($group)
->statePath('attributes')
->options(fn () => $attributes)
->default(fn (Resort $record) => $record->attributes()->pluck('name', 'id'))
)->toArray()
)
->columns(3)
1 Reply
toeknee
toeknee14mo ago
So that should work. I suspect your problem is, you are editing an entry and expecting the defaults to apply?
Want results from more Discord servers?
Add your server