Closed ncskrypt closed 10 years ago
Got it (put in a pull request for yah)
If we overload the relationsToArray()
function exactly as you do for attributesToArray()
it works perfect
/**
* Get the model's relationships, converting field casing if necessary.
*
* @return array
*/
public function relationsToArray()
{
$attributes = parent::relationsToArray();
$convertedAttributes = [];
foreach ($attributes as $key => $value) {
if ($this->enforceCamelCase) {
$key = camel_case($key);
}
$convertedAttributes[$key] = $value;
}
return $convertedAttributes;
}
When grabbing a relationship on a model (not a database column/attribute), it is set in snake_case rather than camelCase. Would be nice to have this added to Eloquence.
Example:
Accessing the Model/Relationship (2 different approaches):
OR:
Output:
The attributes from the database come out as expected in camelCase. Unfortunately the relationship accessor does not. I'll look into possible solutions and let you know if I find anything.