Hi everyone,
I’m facing an issue with array reindexing in a Laravel Livewire component. Here's the situation:
In my Livewire component, I prepare an array with custom keys (IDs) and values (name). The array looks like this when dumped directly in the Livewire component:
array:15 [
9 => "Yayasan Sanbe Farma"
20 => "Tes New Mitra 11"
11 => "Penerbit Erlangga"
2 => "Partner Petra Kovacek"
3 => "Partner Mr. Ulices Haley"
1 => "Partner Alexandro Nienow"
5 => "Mitra ABC"
13 => "Mitra 1"
19 => "LPPM ITB"
8 => "KEMENDIKBUDRISTEK"
10 => "Institut Teknologi Bandung"
21 => "halo testing logi"
22 => "halo aku baru testing nih"
12 => "Bank Negara Indonesia (BNI)"
6 => "Asrama"
]
But when I pass this array to the Blade view and dump it using @dd($options['partner']), the array gets reindexed starting from 1:
array:15 [
1 => "Partner Alexandro Nienow"
2 => "Partner Petra Kovacek"
3 => "Partner Mr. Ulices Haley"
5 => "Mitra ABC"
6 => "Asrama"
8 => "KEMENDIKBUDRISTEK"
9 => "Yayasan Sanbe Farma"
10 => "Institut Teknologi Bandung"
11 => "Penerbit Erlangga"
12 => "Bank Negara Indonesia (BNI)"
13 => "Mitra 1"
19 => "LPPM ITB"
20 => "Tes New Mitra 11"
21 => "halo testing logi"
22 => "halo aku baru testing nih"
]
I need the array to keep its original keys in the Blade view. Here's how I set the data in the Livewire component:
$this->options['partner'] = Partner::getDropdownOptionsStatic('name', Partner::query()->orderBy('name', 'desc'));
Question:
How can I ensure the array retains its original keys when passed from a Livewire component to a Blade view? Is there a specific way to handle this in Livewire or Blade to prevent automatic reindexing?
Thanks in advance!