Search code examples
htmlcheckboxlaravel-livewirelaravel-9

checkbox not displaying checked after putting checked attribute


I have an $lc public array variable in my livewire which contains a boolean. in my view, I have this.

<input @if($lc[$uaf->id]) checked @endif  wire:model.prevent.defer="lc.{{ $uaf->id }}" id="lc.{{ $uaf->id }}" type="checkbox" />

the value of $lc[$uaf->id] is 1 which in boolean represents true. So, it should display a checked box.

but the display is this. 0 it's not checked.

I have already done this

$lc[$uaf->id] = $uaf->classification->for_locational_clearance;

but it's no luck.


Solution

  • in my livewire

        foreach($this->applicant->uafs as $uaf ){
            $this->lc[$uaf->id] = $uaf->classification ? $uaf->classification->for_locational_clearance : false;
        }
    

    and in my blade file

    <input wire:model.prevent.defer="lc.{{ $uaf->id }}" id="lc.{{ $uaf->id }}" type="checkbox" />