Dear Experts!
I’m new with Laravel and Livewire and I don’t know, it is working correctly and I’m thinking it wrong or it should be a mistake.
I want to buld a checkbox list based in many-to-many connections of 2 tables.
I’m collecting the data into
$data_paymethodes like this:
$this->data_paymethodes=Paymethode::orderby(‘name’)->pluck(‘name’,‘id’)->toArray();
here i have indexes from starting 1 and last is 7
I keep the data in this variable to list all the selectable options.
It is registered in my controller as public variable.
I have the actual selection of the options in other variable:
$Checkout = Checkout::findOrFail($id);
$this->paymethodes=$Checkout->paymethodes()->pluck(‘name’,‘paymethode_id’)->toArray();
it is working nice within the controller:
$this->paymethodes:
array:2 [▼
3 => “voucher”
5 => “credit card - 2”
]
All options:
$this->data_paymethodes:
array:7 [▼
2 => “transfer”
6 => “credit card - 1”
5 => “credit card - 2”
4 => “others”
1 => “cash”
7 => “cash at courier”
3 => “voucher”
]
In my blade file I’m proessing with froeach the $data_paymethodes variable
BUT it looks to loosing my ID’s (keys in both above arrays)
{{var_export($paymethodes,1)}}
{{var_export($data_paymethodes ,1)}}
In both DUMP the array key starts from 0 and so I lost the array keys what i have stored in the DB.
<ul class="list-inside">
@foreach($data_paymethodes as $id=>$paymethode)
<li>
<input wire:model="paymethodes"
id="paymethodes.{{ $id }}"
name="paymethodes[]"
type="checkbox"
value="{{$id}}"
/>
<label for="paymethodes.{{ $id }}">{{$id}}-{{$paymethode}}</label>
</li>
@endforeach
</ul>
So the checking of the checkboxes are working more than interesting.
Could anyone help me please?
Thank You
br.
Gergely