Skip to content

Commit

Permalink
Extract values when referencing a nested JSON property in getAttribut…
Browse files Browse the repository at this point in the history
…eFromArray() function. (#52)
  • Loading branch information
iksaku committed Apr 17, 2021
1 parent 3bb8083 commit 7b0a8bb
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/HasJsonRelationships.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ public function getAttribute($key)
return parent::getAttribute($key);
}

/**
* Get an attribute from the $attributes array.
*
* @param string $key
* @return mixed
*/
public function getAttributeFromArray($key)
{
if (Str::contains($key, '->')) {
return $this->getAttributeValue($key);
}

return parent::getAttributeFromArray($key);
}

/**
* Get a plain attribute (not a relationship).
*
Expand Down

0 comments on commit 7b0a8bb

Please sign in to comment.