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. (staudenmeir#52)
  • Loading branch information
iksaku authored and vinkev committed May 10, 2021
1 parent 2527b56 commit 37db132
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 37db132

Please sign in to comment.