I might be wrong, but I believe map() expects an array. You're giving it a function that returns an array. It's not exactly the same thing.
This works for options() because options is expecting a function.
I hope this helps!
Newbie here :)
I cant figure out why a function works in one Field(Select) but not in another(Badge), same function to return an array...
This works:
Select::make('inspection_carried_out')
->options(function () {
return array_filter(\App\Models\Status::pluck('name', 'id')->toArray());
}),
But this doesn't (why?):
Badge::make('external_company_inspection_agreement')
->map(function () {
return array_filter(\App\Models\Status::pluck('badge', 'id')->toArray());
})
Error: Laravel\Nova\Fields\badge::map(): Argument #1 {$map} must of type array, Closure given.
I think that you're on the right track. The only thing that I can think of that is not working is that you have to define the array before passing it to map(). Try:
$badgeMap = \App\Models\Status::pluck('badge', 'id')->toArray();
$badgeMap[null] = 'info'; // Add default for null
Badge::make('external_company_inspection_agreement')
->map($badgeMap);
This should work
Please or to participate in this conversation.