laravelhas-and-belongs-to-manylaravel-nova

Laravel 8 Nova: Customize Reationship BelongsToMany options, displayUsing and resolveUsing don't work


In a Nova resource, I show a BelongsToMany Nova Field. I would want to simply concatenate (prepending) a "check pictogram" before options values of this field, if they are already attached to the Nova resource.

I've tried to use:

BelongsToMany::make(__('Circuits'), 'circuits', Circuit::class)->displayUsing(function ($name) {
            return '...';
        }), 

and

BelongsToMany::make(__('Circuits'), 'circuits', Circuit::class)->resolveUsing(function ($name) {
            return '...';
        }), 

But both don't work (no error, but it doesn't modify the options shown in the Field).

I've also tried Laravel Nova, custom options belongsTo but it doesn't work (the functions options and displayUsingLabels don't modify anything - still, no error is displayed).

I should rather override BelongsToMany class, should I (how?)?


Solution

  • I didn't find a way to prefix with a check or just text, etc. But we can filter out the options values by specifying, in the Nova resource, a method setRelatableX(...) {...}.