Home > OS >  How to make validation for boolean field?
How to make validation for boolean field?

Time:08-31

In laravel I defined bool field

$table->boolean('published')->default(false);

and I defined validation

[published] => nullable|in:0,1

But submitting data

    'published'        => false,

I got validation error(false is passed as epmty value), but value false is valid here. I think I would use

        'published'        => 0,

But that seems not good for me as I want to show that I pass FALSE parameter. How can I change validation rule in this case ?

"laravel/framework": "^9.2",

Thanks in advance!

CodePudding user response:

Validate $request with below rules:

$request->validate([            
    'published' => ['boolean', 'nullable']            
        ]);
  • Related