laravel / nova-issues

554 stars 34 forks source link

Calling `displayUsing` without passing `$attribute` to `Field::make()` doesn't work anymore #6579

Open krenor opened 4 days ago

krenor commented 4 days ago

Description:

We updated our composer dependencies which upgraded Nova from 4.34.3 to 4.35.4 Now it seems that displayUsing, without passing $attribute to the field (e.g. Text), does not show anything in Index Views anymore.

The below example has worked without any issues previously.

Detailed steps to reproduce the issue on a fresh Nova installation:

<?php

namespace App\Nova;

use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;

class User extends Resource
{
    public static $model = \App\Models\User::class;

    public function fieldsForIndex(NovaRequest $request): array
    {
        return [
            Text::make('E-Mail')
                ->displayUsing(fn () => $this->email),
        ];
    }

    public function fields(NovaRequest $request): array
    {
        return [];
    }
}

Additional info

API Response from $.resources[0].fields[0]

{
    "attribute": "e-mail",
    "component": "text-field",
    "compact": false,
    "displayedAs": "wheinemann@example.com",
    "fullWidth": false,
    "helpText": null,
    "indexName": "E-Mail",
    "inline": false,
    "name": "E-Mail",
    "nullable": false,
    "panel": null,
    "placeholder": null,
    "prefixComponent": true,
    "readonly": false,
    "required": false,
    "sortable": false,
    "sortableUriKey": "e-mail",
    "stacked": false,
    "textAlign": "left",
    "uniqueKey": "e-mail-default-text-field",
    "usesCustomizedDisplay": true,
    "validationKey": "e-mail",
    "value": null,
    "visible": true,
    "withLabel": true,
    "wrapping": false,
    "dependentComponentKey": "text.text-field.e-mail",
    "dependsOn": null,
    "dependentShouldEmitChangesEvent": false,
    "asHtml": false,
    "copyable": false
}

4.35.4

Screenshot 2024-11-11 at 14 45 46

4.34.3

Screenshot 2024-11-11 at 14 45 04

"Just reference the attribute"

Yes, referencing any attribute existing in the DB (e.g. id) fixes the example above.
The problem comes with snippets like these where this is not really applicable, which also broke:

Text::make(Lang::get('waitlist.fields.user_fullname'))
    ->displayUsing(function () use ($request) {
        $content = $this->user_id
            ? "<a href='/app/resources/users/{$this->user_id}' class='link-default'>{$this->user_fullname}</a>"
            : $this->user_fullname;

        return "{$content}<br>{$this->phone}";
    })
    ->asHtml()
    ->sortable(),
jansgescheit commented 4 days ago

We just updated our dependencies due to CVE-2024-50345 and now the exact same annoying problem. There is nothing to be found in the Nova release notes.