public function nestedObjectsToArray()
    {
        $attributes = [];

        foreach ($this->getAttributes() as $key => $value) {
            // If the values implements the Arrayable interface we can just call this
            // toArray method on the instances which will convert both objects and
            // collections to their proper array form and we'll set the values.
            if ($value instanceof Arrayable) {
                $attributes[$key] = $value->toArray();
            }
            if (is_array($value)) {
                $attributes[$key] = collect($value)->toArray();
            }
        }

        return $attributes;
    }