In the City Model
public function country_name() { $country = $this->country; return $country->name; }
In the City Nova Resource Text::make('City', function () { return $this->region->country_name(); }),
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am trying to use the computed field to get field of a relation of a relation For example I have a City Resource and a City Belongs to a Region which belongs to a Country I want to use the computed field like this:
In the Nova City resource:
Text::make('Country Name', function () { return $this->region->country->name; }),
And get the error 'trying to get property of non-object'
However if I specify
return $this->region->country
I get value returned as { "id": 5, "name": "France", "type": "2" ... }
Then I tried calling a function and logging the results. logging
Log::debug('Country Name.', ['vn' => $this->country]); return $this->country;
{"country_name":{"App\\Models\\Country":{"id":1,"name":"France" }}}
How do I extract the country name?
Please or to participate in this conversation.