protonemedia / laravel-form-components

A set of Blade components to rapidly build forms with Tailwind CSS (v1.0 and v2.0) and Bootstrap 4/5. Supports validation, model binding, default values, translations, Laravel Livewire, includes default vendor styling and fully customizable!

Home Page:https://protone.media/blog/laravel-form-components-to-rapidly-build-forms-with-tailwind-css-and-bootstrap-4

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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',
];