diff --git a/src/Screen/AsSource.php b/src/Screen/AsSource.php index a2a1e2a27..ae4aad9fe 100644 --- a/src/Screen/AsSource.php +++ b/src/Screen/AsSource.php @@ -22,10 +22,16 @@ trait AsSource * * @return mixed|null The value of the field, or null if the field is not found. */ - public function getContent(string $field) + public function getContent(string $field): mixed { - return Arr::get($this->toArray(), $field) // Try to get the field value from the object's array representation. + // When field does not contain a dot, it is a simple field name. + // And we not need to use cast model to array for this case. + if (!str_contains($field, '.')) { + return $this->getAttribute($field); + } + + return $this->getAttribute($field) // Try to get the field value from the object's attributes. ?? Arr::get($this->getRelations(), $field) // Try to get the field value from the object's relations. - ?? $this->getAttribute($field); // Try to get the field value from the object's attributes. + ?? Arr::get($this, $field); // Try to get the field value from the object's array representation. } }