Answers for "livewire model bind item in array"

PHP
0

livewire model bind item in array

#Using a multi-dimensional array that looks like this:
$data = [
   1 => ['name' => 'Name', 'completed' => 0],
   2 => ['name' => 'Name 2', 'completed' => 1],
];
#Bind items like so:
@foreach ($items as $item)
   <x-input wire:model="data.{{ $item->id }}.name" type="text" />
   <x-input wire:model="data.{{ $item->id }}.completed" type="checkbox" />
@endforeach
Posted by: Guest on October-19-2021

Browse Popular Code Answers by Language