Home > Software engineering >  Check/uncheck checkboxes in the Laravel Nova Action Modal with BooleanGroup
Check/uncheck checkboxes in the Laravel Nova Action Modal with BooleanGroup

Time:11-27

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?

CodePudding user response:

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,
        ];
    }),
];
  • Related