Skip to content

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

@krenor

Description

@krenor
  • Laravel Version: 10.48.22
  • Nova Version: 4.35.4
  • PHP Version: 8.2.8
  • Database Driver & Version: mariadb 10.8
  • Operating System and Version: OSX 14.5 (23F79)
  • Browser type and version: Chrome 130.0.6723.117 (arm64)

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(),

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified bug by the Nova teamfix incomingA fix is in review

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions