diff --git a/src/AbstractSerializer.php b/src/AbstractSerializer.php index 2c57ad1..53dcd7a 100644 --- a/src/AbstractSerializer.php +++ b/src/AbstractSerializer.php @@ -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); @@ -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)))); + } }