orlyapps / nova-belongsto-depend

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

Creating select field does show amount of values but the values appear empty in nova #31

Closed Alrektii closed 5 years ago

Alrektii commented 5 years ago

Either : this

 NovaBelongsToDepend::make('Country')
        ->options(
                \App\Country::all()
          ),

or

NovaBelongsToDepend::make('Country')
     ->options(
            [
               'Text',
                'Text 2',
                'Text 3'
           ]
       ),

Give me : image

it is the correct amount of values all the time , but there does not seem to be a title whereas when I use the normal 'BelongsTo' the values are there perfectly fine.

Am I doing something wrong? or is this a bug in the package, please let me know.

Alrektii commented 5 years ago

Edit: When a random value is selected and you press save to database , the selected value is saved to the database

stezani commented 5 years ago

I have the same problem with my accessors. In my case i have a model called Employee and in my table two columns first_name and last_name. I have defined in my model an Accessor getFullNameAttribute that is used in my nova resource in public static $title = 'full_name';

orlyapps commented 5 years ago

Hello,

you need to pass an array to the options method like this:

NovaBelongsToDepend::make('Country')->options([['id' => 1, 'name' => 'test'], ['id' => 2, 'name' => 'test2']]), Or use the tipp from @stezani 👍

eman-abdulwahab commented 4 years ago

@orlyapps I am facing the same exact issue even though my options are formatted the same way you have it.. is there any other reason to that? Also the values are correct and are being added to the database. I just can't view them

realunreals commented 4 years ago

@orlyapps I am facing the same exact issue even though my options are formatted the same way you have it.. is there any other reason to that? Also the values are correct and are being added to the database. I just can't view them

If you update resource title to 'name' you can solve the problem. It should be public static $title = 'name';

eman-abdulwahab commented 4 years ago

@orlyapps I am facing the same exact issue even though my options are formatted the same way you have it.. is there any other reason to that? Also the values are correct and are being added to the database. I just can't view them

If you update resource title to 'name' you can solve the problem. It should be public static $title = 'name';

Thank you very much this works now. do you have an idea on how to set a default selected value?