ziffmedia / nova-select-plus

A Laravel Nova Select Field
MIT License
95 stars 26 forks source link

Added 'usingEditLabel' method #7

Closed pecuchet closed 4 years ago

pecuchet commented 4 years ago

Hello,

Much like usingIndexLabel and usingDetailLabel, this allows to customize the label on the edit screen. For example:

SelectPlus::make('States Lived In', 'statesLivedIn', State::class)
  ->label('name')
  ->usingEditLabel(function ($model, $label) {
    return "{$model->nicePrefixAttribute}:{$model->$label}";
  });

Fixes #6

pecuchet commented 4 years ago

Any chance this can be merged?

ralphschindler commented 4 years ago

Hi, can you take a look at:

https://github.com/ziffmedia/nova-select-plus/pull/8

It looks like label is only ever really used as the label for selectable values, so I think its prob best to just use that API, thoughts?

edit: this appears to be closer to your original suggestion in #6 perhaps?

pecuchet commented 4 years ago

Hi @ralphschindler, thanks for looking into it. The reason why I proposed the usingEditLabel method, was because of this line in the Controller:

$query->where($field->label, 'LIKE', "%{$search}%");

I couldn't immediately find a solution for $field->label when it is callable instead of a string. If it works with your suggestion, fine for me ;-)

ralphschindler commented 4 years ago

Fixed in v1.0.5, thanks for the input and ideas!