Skip to content
This repository was archived by the owner on Jan 2, 2023. It is now read-only.
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
17 changes: 17 additions & 0 deletions src/AbstractSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public function getAttributes($model, array $fields = null)
*/
public function getRelationship($model, $name)
{
if (stripos($name, '-')) {
$name = $this->replaceDashWithUppercase($name);
}

if (method_exists($this, $name)) {
$relationship = $this->$name($model);

Expand All @@ -64,4 +68,17 @@ public function getRelationship($model, $name)
return $relationship;
}
}

/**
* Removes all dashes from relationsship and uppercases the following letter.
* @example If relationship parent-page is needed the the function name will be changed to parentPage
*
* @param string Name of the function
*
* @return string New function name
*/
private function replaceDashWithUppercase($name)
{
return lcfirst(implode('', array_map('ucfirst', explode('-', $name))));
}
}