In my Livewire View
@foreach ($diagnosisList as $row)
<div class="col-6 mb-2">
<div class="d-flex align-items-center">
<label class="form-check mb-0 w-120px">
<input wire:model.debounce.1000ms='diagnoses.{{ $row->id }}'
data-name="{{ $row->name }}"
class="form-check-input" type="checkbox" value="{{ $row->id }}">
<span class="form-check-label font-13 fw-medium">{{ $row->name }}</span>
</label>
</div>
</div>
@endforeach
In my Livewire Class (controller):
public function updatedDiagnoses($value, $id)
{
}
In livewire, i need to get $row->name in updatedDiagnoses() for checked event and push them into array.
How to do this?
2
Answers
You should post the format of your data, however I assume you have a $diagnosisList array containing the models and a $diagnosis array containing checkbox values indexed by record id
The only way for your configuration is to read the row from DB :
I can’t understand the ".debounce.1000ms"
If you are using Livewire 3 perhaps you should change it with .live to let the backend call happen on change:
It would be also advisable to add a wire:key in the @foreach content:
You need to define a public property in your livewire to hold the array of checked diagnosis names and then update
updatedDiagnoses
to add/remove the diagnosis name from$checkedDiagnoses
base on whether the checkbox is checked/unchecked. You need to pass both value and name of the diagnosis to theupdatedDiagnoses
using js and then create theupdatedCheckedDiagnoses
in your livewire:Livewire Class (controller)
Livewire View