Search code examples
laravellaravel-nova

Check/uncheck checkboxes in the Laravel Nova Action Modal with BooleanGroup


I use Laravel Nova. On a resource I have an Action. The fields method returns a BooleanGroup Field:

return [
    BooleanGroup::make('Tagss')->options(
        [
            'one',
            'two',
            'three',
            'four'
        ]
    ),
];

Result:

enter image description here

I don't know how to pre-check checkboxes. Let's say 'two' should be checked when the modal loads, how to do this?


Solution

  • Use default function. Set true for the default value

    return [
        BooleanGroup::make('Tags')->options(
            [
                'one',
                'two',
                'three',
                'four'
            ]
        )->default(function ($request) {
            return [
                'one' => false,
                'two' => true,
                'three' => false,
                'four' => false,
            ];
        }),
    ];