Can't use x-form-select using query
andrecuellar opened this issue · comments
I'm using livewire query to get options for select, for example, I have this in my blade:
<x-form-select
name="area_group[]"
:options="$area_group" />
and in my livewire this:
public
$area_group;
public function mount()
{
$this->area_group = AreaGroup::query()->select('id', 'name')->get();
}
but the result on the view is a select options in json
<option value="0">
{"id":1,"name":"\u30cf\u30ef\u30a4"}
</option>
And I want to get that ID as value and name as option, how can I solve it?
$area_group can not be a collection/array of models, it must be in the format of a key/value array.
Example:
$area_group = [
111 => 'Group Name 1',
112 => 'Group Name 2',
];
I have put together a gist to help you with this.
https://gist.github.com/mrl22/9693be99d155213400d6f3eb09657ac5