I haven't played with this code, but I wouldn't set the value of the input, but maybe try wire:model="type.selectedtypes". It would help to know what data is in $this->initial_cargo_types.
Jul 22, 2020
11
Level 28
Laravel Livewire: How to bind checkbox selected values to component array
Hello, Could anybody help me to solve following issue, I am trying to bind only selected checkbox values to array in my livewire component as below, but it does not work
Component
use Livewire\Component;
use App\Point;
class AddNewTrip extends Component
{
public $selectedtypes;
public $initial_cargo_types;;
public function mount($cargoTypes)
{
$this->initial_cargo_types = $cargoTypes;
}
}
Blade
@foreach($initial_cargo_types as $type)
<div class="mt-1">
<label class="inline-flex items-center">
<input type="checkbox" value="{{ $type->id }}" wire.model="selectedtypes" class="form-checkbox h-6 w-6 text-green-500">
<span class="ml-3 text-sm">{{ $type->name }}</span>
</label>
</div>
@endforeach
Please or to participate in this conversation.