Benjacho / belongs-to-many-field-nova

Belongs To Many field Laravel nova to represent many to many relationship in field.
MIT License
157 stars 81 forks source link

Name field rendering problem in version 4.26 #128

Open MicaiasROliveira opened 1 year ago

MicaiasROliveira commented 1 year ago

When creating and updating, there is a problem rendering the field name, for example when I do:

BelongsToManyField::make('Roles', 'roles', Role::class),

The name Roles does not appear and the multiselect is at the beginning where the name should be. I fixed this by downgrading to nova 4.25.*

Kaylakaze commented 1 year ago

Same issue.

romaincherot commented 1 year ago

Same issue for me, the label does not appear (and nothing in html inspector, it's not just hidden) :

    // In Nova ressource
    Number::make('Position')
        ->nullable(),

    BelongsToManyField::make('Artistes participant :', 'artists', Artist::class)
        ->optionsLabel('title')
        ->hideFromIndex(),

    BelongsToManyField::make('Styles :', 'styles', Style::class)
        ->optionsLabel('title')
        ->hideFromIndex(),

render like this : Screenshot

bigperson commented 11 months ago

I have some problem Nova 4.32.6

ZakariaTlilani commented 11 months ago

Same issue Nova 4.32.11 has anyone found a solution ? i read the entier code but found nothing that could be the reason why :/

enricv commented 9 months ago

same problem

enricv commented 9 months ago

Solved... change in BelongsToManyField.php this code: image

to

image

then it works: image

Now is not necessary to use optionLabel call. Field gets name from make atribute parameter.

image

LeX142 commented 9 months ago
  1. Create a new class named CustomBelongsToManyField.
  2. Extend it from the original BelongsToManyField.
  3. Create a method named jsonSerialize, add withLabel to the serialization.
   public function jsonSerialize(): array
   {
        return array_merge(parent::jsonSerialize(),['withLabel' => $this->withLabel]);
   }
  1. Use the new class in your Nova4 resources. and get label for field
enricv commented 9 months ago

Thanks