diff --git a/composer.json b/composer.json index 5c6e13f..db76dcd 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "rspeekenbrink/laravel-menu", + "name": "danieleisenhardt/laravel-menu", "description": "Simple menu generation in Laravel", "type": "library", "license": "MIT", diff --git a/src/MenuItem.php b/src/MenuItem.php index ae32cb5..276eeec 100644 --- a/src/MenuItem.php +++ b/src/MenuItem.php @@ -222,6 +222,31 @@ public function toArray() return array_merge($this->attributesToArray(), $this->variablesToArray()); } + /** + * Convert the model's attributes to an array. + * + * @return array + */ + public function attributesToArray() + { + // If an attribute is a date, we will cast it to a string after converting it + // to a DateTime / Carbon instance. This is so we will get some consistent + // formatting while accessing attributes vs. arraying / JSONing a model. + $attributes = $this->addDateAttributesToArray( + $attributes = $this->getArrayableAttributes() + ); + + + // Here we will grab all of the appended, calculated attributes to this model + // as these attributes are not really in the attributes array, but are run + // when we need to array or JSON the model for convenience to the coder. + foreach ($this->getArrayableAppends() as $key) { + $attributes[$key] = $this->mutateAttributeForArray($key, null); + } + + return $attributes; + } + /** * Convert the object to its JSON representation. *