Skip to content

Laravel Nova - concatenation of JSON properties from a field #2310

@antlusher

Description

@antlusher

I have a JSON field called name with keys as follows: first, last, title.

On the index page, I wish to join all into one column - the full name.

At the moment I have this code, which does not work:

    Text::make('Name', function () { return $this->name->first.' '.$this->name->last; })

But this does work, which shows the title of the user:

    Text::make('Name', 'name->title')

Update:

I have the following in

app/User.php

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'name' => 'json',
    ];

In Nova/User.php

    Text::make('Name', function () 
    { 
     return $this->name->first; 
    }),

Error:
Trying to get property 'first' of a non-object
I


The following returns an Object called Value and renders the 'title':

Text::make('Name', 'name->title')

The following returns an Object called Value and renders the the complete Object as a string:

Text::make('Name', 'name')

Value Object

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions