tanmay_das
2 years ago
853
10
Laravel

Inserting checkbox value into database

Posted 2 years ago by tanmay_das

In my view I have a checkbox like this:

<input type="checkbox" name="isnegotiable" value="1"> Negotiable

And in my migration file I am setting the default value of this field to 0:

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

My intention is to set this value to 1 only when the user selects the checkbox. But it turns out, even if the user selects the checkbox, isnegotiable column gets filled with 0, not 1.

Because I cannot pass the isnegotiable as the argument of create(request()) method as it throws isnegotiable column cannot be null error. What should I do?

Please sign in or create an account to participate in this conversation.