You should leave us with a little bit of code. We can't help you without any code.
Submit a default value if a checkbox is unchecked
Hi,
I did create a form. In that form, I have one checkbox. When it is check, it's submit a value (1) to the server. This checkbox is not mandatory.
When I submit the form, if the checkbox is unchecked, I have an error : "Column 'xxxx' cannot be null.
I would like to know if it possible, in the validation rules or in the controller to assign the value 0 by default if the checkbox is unchecked. I don't want the column to be null.
I already tried to add a default value to the column in the migration file. It's not working as I expect.
Thanks for your help,
If you're using php7+, you could also simplify that a bit with the null coalesce operator.
if($request->get('featured') == null){
$featured = 0;
} else {
$featured = request('featured');
}
becomes just $featured = $request->get('featured') ?? 0;
Please or to participate in this conversation.