Beispiel #1
0
 /**
  * Convert the model's attributes to an array.
  *
  * @return array
  */
 public function attributesToArray()
 {
     $attributes = parent::attributesToArray();
     // Because the original Eloquent never returns objects, we convert
     // MongoDB related objects to a string representation. This kind
     // of mimics the SQL behaviour so that dates are formatted
     // nicely when your models are converted to JSON.
     foreach ($attributes as $key => &$value) {
         if ($value instanceof MongoId) {
             $value = (string) $value;
         }
     }
     return $attributes;
 }
Beispiel #2
0
 /**
  * Convert the model's attributes to an array.
  *
  * @return array
  */
 public function attributesToArray()
 {
     $attributes = parent::attributesToArray();
     // Because the original Eloquent never returns objects, we convert
     // MongoDB related objects to a string representation. This kind
     // of mimics the SQL behaviour so that dates are formatted
     // nicely when your models are converted to JSON.
     foreach ($attributes as $key => &$value) {
         if ($value instanceof MongoId) {
             $value = (string) $value;
         }
     }
     // Convert dot-notation dates.
     foreach ($this->getDates() as $key) {
         if (str_contains($key, '.') and array_has($attributes, $key)) {
             array_set($attributes, $key, (string) $this->asDateTime(array_get($attributes, $key)));
         }
     }
     return $attributes;
 }
Beispiel #3
0
 /**
  * Convert the model's attributes to an array.
  *
  * @return array
  */
 public function attributesToArray()
 {
     $attributes = parent::attributesToArray();
     // Because the original Eloquent never returns objects, we convert
     // MongoDB related objects to a string representation. This kind
     // of mimics the SQL behaviour so that dates are formatted
     // nicely when your models are converted to JSON.
     foreach ($attributes as $key => &$value) {
         if ($value instanceof MongoId) {
             $value = (string) $value;
         } else {
             if (starts_with($key, '_')) {
                 $camelKey = camel_case($key);
                 // If we can find a method that responds to this relation we
                 // will remove it from the output.
                 if (method_exists($this, $camelKey)) {
                     unset($attributes[$key]);
                 }
             }
         }
     }
     return $attributes;
 }