1
votes

I have a Laravel application that contains an entity with a HasOne relationship from parent to child.

I'm now introducing Laravel Nova, and would like the parent's detail view to include all the fields from the child without my user having to click into it as you do with a Nova BelongsTo or HasOne field. They would look like a single record.

Assuming that I cannot modify the structure of the application, is there an existing method to do this? Can I override the detail screen with my own code? The Nova documentation doesn't address this specific use case, nor can I find any other questions on this topic online.

I don't care about needing to create or edit the entries, Nova will just be used to view them in this case.

Thanks

1

1 Answers

0
votes

There is not an easy way to display all of the child's details in the parent's details view.

The best solution is to use the title attribute on the child. This lets you customize the text representation of the child in the parent's index view and details view.

By default, you have:

public static $title = 'id';

Can be replaced this with:

public static $title = 'name';

Or:

public function title()
{
    return $this->name . '(' . $this->email . ')';
}

Source: https://nova.laravel.com/docs/1.0/resources/relationships.html#title-attributes