public function relationsToArray()
{
$attributes = array();
foreach ($this->relations as $key => $value) {
if (in_array($key, $this->hidden)) {
continue;
}
// If the values implements the Arrayable interface we can just call this
// toArray method on the instances which will convert both models and
// collections to their proper array form and we'll set the values.
if ($value instanceof ArrayableInterface) {
$relation = $value->toArray();
} elseif (is_null($value)) {
$relation = $value;
}
// If the relationships snake-casing is enabled, we will snake case this
// key so that the relation attribute is snake cased in this returned
// array to the developer, making this consisntent with attributes.
if (static::$snakeAttributes) {
$key = snake_case($key);
}
// If the relation value has been set, we will set it on this attributes
// list for returning. If it was not arrayable or null, we'll not set
// the value on the array because it is some type of invalid value.
if (isset($relation)) {
$attributes[$key] = $relation;
}
}
return $attributes;
}