Have you tried to remove .lazy ?
Unchecking Checkbox returns false?
This is one confusing me!
I have a form with a foreach looping over positions creating input checkboxes for each position. The checked boxes go into an array.
<input wire:ignore.self class="form-check-input" type="checkbox" value="{{ $position->id }}" name="selectedPositions" wire:model.lazy="selectedPositions.{{ $position->id }}" />
Everything works fine, except when I uncheck one, that is to say I accidentally checked the wrong one, it stays in the array but has a value of "false".
^ array:4 [▼
1 => "1"
2 => false
3 => "3"
7 => "7"
]
This throws an error on the save with an Integrity constraint violation on the "false".
$group->positions()->sync($this->selectedPositions);
How can I either, 1 - get around the error, or 2 - get the checked box removed from the array when I actually uncheck it?
Thanks for the help!
@dmhall0 What about
$group->positions()->sync(array_filter($this->selectedPositions));
Also here is a similar solution
https://laracasts.com/discuss/channels/livewire/livewire-checkboxes-array-with-pluck
Please or to participate in this conversation.