1

I'm having trouble with Laravel's Form::model() construct. I was able to populate it with my model data but the checkboxes aren't being checked. The values are being set to 1 or 0 (courtesy of Eloquent calling a "boolean" a "tinyint" in MySQL), but I can't see how to use the Form::model() approach and set that checked attribute if the value coming is an integer and not a boolean (hence why I think Form Model Binding for checkboxes isn't working).

I'm specifying this in my view:

{{ Form::checkbox('hasDiscount') }}

And the form builder is returning this:

<input name="hasDiscount" type="checkbox" value="1" id="hasDiscount">

1 Answer 1

0

I think it's not really related to data-value. The value could be 'true' and the checked attribute could be false as well.

If you want to display checkbox with checked attribute, you can try my wait (it's not the best, I admit):

Form::model($model)
  Form::checkbox('name', null, $model->value)
Form::close()

The third parameter could be convert to false if the value of model is null or 0 and the checkbox is not checked. otherwise, it's checked.

If you have another idea, please share it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.