Closed mertasan closed 3 years ago
Workaround (or correct usage):
$category->getCategoryTree()->map(function ($item) {
return ['value' => $item["id"], 'text' => $item['name']];
})->all();
This is something I don't think I'm going to focus on fixing right now, as I'm not really sure how I would in the first place. Since you can easily call ->values()
on a collection to reset the indexes, or use ->map()
to transform the collection like you showed in your examples, I don't see this as a high priority to resolve.
In my own projects, I'll usually map out simple values like that.
An alternative to mapping out an eloquent collection like that is to just define the value-field
and text-field
on the custom select.
Example:
<x-custom-select
wire:model="userId"
:options="\App\Models\User::get(['id', 'name'])"
value-field="id"
text-field="name"
/>
This is how I get the category list:
Output:
This is the result:
The reason is that array index numbers do not start from 0.
It seems to work fine if I use it like this:
Output:
Result:
Context