orlyapps / nova-belongsto-depend

Larave Nova BelongsTo Field with Dependcy
MIT License
182 stars 65 forks source link

Custom display name, Different column to display not showing #121

Open amitsingh9thjan opened 2 years ago

amitsingh9thjan commented 2 years ago

NovaBelongsToDepend::make('Shows', 'shows', \App\Nova\Shows::class) ->placeholder('-- Select Show --') // Add this just if you want to customize the placeholder ->options(Shows::all()) ->display(function($shows){ return $shows->title . ' - ' . $shows->en_title; }),

I'm trying this but it's not showing display attribute content.

ikramooe commented 2 years ago

any solution i'm having the same problem

mageto commented 1 year ago

You can try to map the array like below and see if it works for you.

->optionsResolve(function ($shows) {

             return $shows->get(['title', 'en_title'])

               ->pluck('title', 'en_title')

               ->map(function($title, $key) {

                     return ['title' => $key, 'en_title' => $key . ' - ' . $en_title];

               })

               ->values()

                ->toArray();

           })