Livewire Checkbox On foreach Loop I have a simple checkbox that i want has tick on 0 and untick on 1 value on every row, but the strange is doesnt get the id
<input type='checkbox' wire:model="hasnotify.{{ $service->id }}" class="py-2 form-checkbox text-green-600">
public function updatedHasnotify()
{
// dd("$this->serviceID");
Service::find($this->serviceID)->update(['hasnotify' => $this->hasnotify]);
}
when i dd the serviceID i get null
When i dd $this->hasnotify i get >
array:1 [▼
12 => true
]
that is correct, but how i can separate that value to find the '12' id and take the true value?
I dont know if its 'dump' approach but it worked
@if ($service->hasnotify == 1)
<input type='checkbox' checked="true" value="{{$service->id}}" wire:click="hasnotify ({{ $service->id }},0)">
@else
<input type='checkbox' value="{{$service->id}}" wire:click="hasnotify ({{ $service->id }},1)">
@endif
public function hasnotify($serviceID, $action)
{
Service::find($serviceID)->update(['hasnotify' => $action]);
}
@chris1989
You can do it as :
// blade
<input wire:model="check.{{$service->id}}" type="checkbox" @if ({{$service->hasNotify}}) checked @endif >
// backend file
public function updatedCheck($value, $id){
Service::find($id)->update(['hasNotify' => $value]);
}
Please sign in or create an account to participate in this conversation.