Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Dave Wize's avatar

I have a nova bollean group field and it is checked on default.

I want to have a default value of false but I cannt get it to work.

Maybe the issue is that it is a field on a computed property (a mutator). Here is the nova resource code

            BooleanGroup::make('Booleans')->options([
                'no_bill_brooklyn' => 'No Bill Brooklyn',
                'no_bill_upstate' => 'No Bill Upstate',
                'no_book_brooklyn' => 'No Book Brooklyn',
                'no_book_upstate' => 'No Book Upstate',
                'wta_brooklyn' => 'Wta Brooklyn',
                'wta_upstate' => 'Wta Upstate',
                'pot_brooklyn' => 'Pot Brooklyn',
                'pot_upstate' => 'Pot Upstate',
                'must_pay' => 'Must Pay',
                'to_go_collect' => 'To Go Collect',
            ]),

And here is the attribute method on the model class.

 protected function booleans(): Attribute
    {
        return Attribute::make(
            get: fn () => [
                'no_bill_brooklyn' => $this->no_bill_brooklyn === 'n' ? false : true,
                'no_bill_upstate' => $this->no_bill_upstate === 'n' ? false : true,
                'no_book_brooklyn' => $this->no_book_brooklyn === 'n' ? false : true,
                'no_book_upstate' => $this->no_book_upstate === 'n' ? false : true,
                'wta_brooklyn' => $this->wta_brooklyn === 'n' ? false : true,
                'wta_upstate' => $this->wta_upstate === 'n' ? false : true,
                'pot_brooklyn' => $this->pot_brooklyn === 'n' ? false : true,
                'pot_upstate' => $this->pot_upstate === 'n' ? false : true,
                'must_pay' => $this->must_pay === 'n' ? false : true,
                'to_go_collect' => $this->to_go_collect === 'n' ? false : true,
            ],
            set: fn ($value) => [
                'no_bill_brooklyn' => $value['no_bill_brooklyn'] === true ? 'y' : 'n',
                'no_bill_upstate' => $value['no_bill_upstate'] === true ? 'y' : 'n',
                'no_book_brooklyn' => $value['no_book_brooklyn'] === true ? 'y' : 'n',
                'no_book_upstate' => $value['no_book_upstate'] === true ? 'y' : 'n',
                'wta_brooklyn' => $value['wta_brooklyn'] === true ? 'y' : 'n',
                'wta_upstate' => $value['wta_upstate'] === true ? 'y' : 'n',
                'pot_brooklyn' => $value['pot_brooklyn'] === true ? 'y' : 'n',
                'pot_upstate' => $value['pot_upstate'] === true ? 'y' : 'n',
                'must_pay' => $value['must_pay'] === true ? 'y' : 'n',
                'to_go_collect' => $value['to_go_collect'] === true ? 'y' : 'n',
            ],
        );
    }

Any help?

0 likes
1 reply
Dave Wize's avatar
Dave Wize
OP
Best Answer
Level 18

I got it. Simple. I just switched the getter to be false unless it is 'y' in the db (my db column is a enum:y,n).

            get: fn () => [
                'no_bill_brooklyn' => $this->no_bill_brooklyn === 'y' ? true : false,
                'no_bill_upstate' => $this->no_bill_upstate === 'y' ? true : false,
                'no_book_brooklyn' => $this->no_book_brooklyn === 'y' ? true : false,
                'no_book_upstate' => $this->no_book_upstate === 'y' ? true : false,
                'wta_brooklyn' => $this->wta_brooklyn === 'y' ? true : false,
                'wta_upstate' => $this->wta_upstate === 'y' ? true : false,
                'pot_brooklyn' => $this->pot_brooklyn === 'y' ? true : false,
                'pot_upstate' => $this->pot_upstate === 'y' ? true : false,
                'must_pay' => $this->must_pay === 'y' ? true : false,
                'to_go_collect' => $this->to_go_collect === 'y' ? true : false,
            ],

Please or to participate in this conversation.