Dosmukhanbet
2 months ago
1319
1
Laravel

Laravel Livewire: How to bind checkbox selected values to component array

Posted 2 months ago by Dosmukhanbet

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 sign in or create an account to participate in this conversation.