Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fast Attribute Access #2921

Merged
merged 2 commits into from
Nov 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/Screen/AsSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
}
Loading