当前位置: 首页>>代码示例>>PHP>>正文


PHP Model::attributesToArray方法代码示例

本文整理汇总了PHP中Illuminate\Database\Eloquent\Model::attributesToArray方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::attributesToArray方法的具体用法?PHP Model::attributesToArray怎么用?PHP Model::attributesToArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Database\Eloquent\Model的用法示例。


在下文中一共展示了Model::attributesToArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: toArray

 /**
  * Get the instance as an array.
  *
  * @return array
  */
 public function toArray()
 {
     $model = [];
     foreach ($this->model->attributesToArray() as $attribute => $value) {
         $model[$attribute] = $this->{$attribute};
         if (is_object($model[$attribute]) && is_callable([$model[$attribute], 'toArray'])) {
             $model[$attribute] = $model[$attribute]->toArray();
         }
     }
     foreach ($this->model->getRelations() as $relationName => $relation) {
         try {
             $pivotRelationName = $relation->relationName;
         } catch (Exception $e) {
             // Fall though...
         }
         if (isset($pivotRelationName)) {
             $relationName = $pivotRelationName;
         }
         if (is_object($relation) && is_callable([$relation, 'toArray'])) {
             $model[$relationName] = $relation->toArray();
         } else {
             $model[$relationName] = $relation;
         }
     }
     if (!empty($this->additionalAttributes)) {
         foreach ($this->additionalAttributes as $attribute) {
             $model[$attribute] = $this->{$attribute};
             if (is_object($model[$attribute]) && is_callable([$model[$attribute], 'toArray'])) {
                 $model[$attribute] = $model[$attribute]->toArray();
             }
         }
     }
     return $model;
 }
开发者ID:artissant,项目名称:laravel,代码行数:39,代码来源:ViewModel.php

示例2: convert

 /**
  * Convert a value to XML.
  *
  * @param Model $value
  * @param SimpleXMLElement $element
  * @return SimpleXMLElement
  * @throws CantConvertValueException
  */
 public function convert($value, SimpleXMLElement $element) : SimpleXMLElement
 {
     if (!$value instanceof Model) {
         throw new CantConvertValueException("Value is not a model.");
     }
     return $this->prepareElement(collect($value->attributesToArray()), $element);
 }
开发者ID:fetchleo,项目名称:laravel-xml,代码行数:15,代码来源:ModelConverter.php

示例3: bind

 /**
  * Bind Model to the form
  *
  * @param Model|Array $model
  * @return $this
  */
 public function bind($model = [])
 {
     /**
      * Cast eloquent model to array
      */
     $data = $model instanceof Model ? $model->attributesToArray() : $model;
     $this->bind = $this->collection->make($data);
     return $this;
 }
开发者ID:SkysoulDesign,项目名称:TempArk,代码行数:15,代码来源:FormBuilder.php

示例4: decorate

 /**
  * Decorates a single Eloquent Model
  *
  * @param Model $item
  *
  * @return array
  */
 public function decorate(Model $item)
 {
     $returnObject = [];
     foreach ($item->attributesToArray() as $attribute => $value) {
         if (isset($this->decorateTable[$attribute])) {
             $returnObject[$this->decorateTable[$attribute]] = $value;
         }
     }
     return $returnObject;
 }
开发者ID:ionutz2k2,项目名称:snippet-catalog,代码行数:17,代码来源:SnippetDecorator.php

示例5: serializeEloquentModel

 /**
  * @param Model $value
  *
  * @return array
  */
 protected function serializeEloquentModel(Model $value)
 {
     $stdClass = (object) $value->attributesToArray();
     $data = $this->serializeData($stdClass);
     $data[self::CLASS_IDENTIFIER_KEY] = get_class($value);
     $methods = RelationshipPropertyExtractor::getRelationshipAsPropertyName($value, get_class($value), new ReflectionClass($value), $this);
     if (!empty($methods)) {
         $data = array_merge($data, $methods);
     }
     return $data;
 }
开发者ID:nilportugues,项目名称:serializer-eloquent-driver,代码行数:16,代码来源:Driver.php

示例6: attributesToArray

 /**
  * Convert the model's attributes to an array.
  *
  * @inheritdoc
  */
 public function attributesToArray()
 {
     // unset date values that are 0, so they don't cause problems with serializeDate()
     foreach ($this->getDates() as $key) {
         if (!isset($this->attributes[$key])) {
             continue;
         }
         // 0 should be considered 'unset' aswell
         if (0 === $this->attributes[$key]) {
             $this->attributes[$key] = null;
         }
     }
     $attributes = parent::attributesToArray();
     // make sure that our date values are strings
     foreach ($this->getDates() as $key) {
         if ($attributes[$key] instanceof \DateTime) {
             $attributes[$key] = $attributes[$key]->format($this->getDateFormat());
         }
     }
     return $attributes;
 }
开发者ID:czim,项目名称:aalberts-pxlcms,代码行数:26,代码来源:CmsModel.php

示例7: attributesToArray

 /**
  * 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;
 }
开发者ID:RTLer,项目名称:laravel-mongodb,代码行数:25,代码来源:Model.php

示例8: consumeModel

 /**
  * Lets the model consume the old one
  * @param  Model  $model The old model
  * @return $this
  */
 public function consumeModel(Model $model)
 {
     $this->consumedModel = $model;
     $this->consumedModelProps = array_merge($model->attributesToArray(), $model->relationsToArray());
     return $this;
 }
开发者ID:sebwas,项目名称:multi-model-authentication,代码行数:11,代码来源:ConsumesModel.php

示例9: attributesToArray

 /**
  * Convert the model's attributes to an array.
  *
  * @inheritdoc
  */
 public function attributesToArray()
 {
     // unset date values that are 0, so they don't cause problems with serializeDate()
     foreach ($this->getDates() as $key) {
         if (!isset($this->attributes[$key])) {
             continue;
         }
         // 0 should be considered 'unset' aswell
         if (0 === $this->attributes[$key]) {
             $this->attributes[$key] = null;
         }
     }
     return parent::attributesToArray();
 }
开发者ID:czim,项目名称:laravel-pxlcms,代码行数:19,代码来源:CmsModel.php

示例10: getModelData

 /**
  * @param Driver $serializer
  * @param Model  $model
  *
  * @return array
  */
 protected static function getModelData(Driver $serializer, Model $model)
 {
     $stdClass = (object) $model->attributesToArray();
     $data = $serializer->serialize($stdClass);
     $data[Serializer::CLASS_IDENTIFIER_KEY] = get_class($model);
     return $data;
 }
开发者ID:marcogrueter,项目名称:serializer-eloquent-driver,代码行数:13,代码来源:RelationshipPropertyExtractor.php

示例11: attributesToArray

 /**
  * Convert the model's attributes to an array.
  *
  * @return array
  */
 public function attributesToArray()
 {
     $attributes = parent::attributesToArray();
     // 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;
 }
开发者ID:brunojk,项目名称:laravel-rethinkdb,代码行数:16,代码来源:Model.php

示例12: attributesToArray

 /**
  * {@inheritdoc}
  */
 public function attributesToArray()
 {
     $attributes = parent::attributesToArray();
     foreach ($attributes as $key => $value) {
         if (in_array($key, $this->encrypted) && !empty($this->attributes[$key])) {
             $attributes[$key] = Crypt::decrypt($value);
         }
     }
     return $attributes;
 }
开发者ID:df-arif,项目名称:df-core,代码行数:13,代码来源:BaseModel.php

示例13: getInputForModel

 /**
  * Return the attributes for a particular model as an array of input values
  *
  * @param   Model $model        The model for which we would like to return the input values
  * @param   string $prefix      The prefix that needs to be added to the input
  * @return array
  */
 public function getInputForModel($model, $prefix = '')
 {
     return $this->getPrefixedInput($model->attributesToArray(), $prefix);
 }
开发者ID:ixudra,项目名称:core,代码行数:11,代码来源:BaseInputHelper.php

示例14: attributesToArray

 /**
  * @return array
  */
 public function attributesToArray()
 {
     $attributes = parent::attributesToArray();
     foreach ($this->jsonFields as $field) {
         if (array_key_exists($field, $attributes)) {
             $attributes[$field] = json_decode($attributes[$field], true);
         }
     }
     foreach ($this->booleanFields as $field) {
         if (array_key_exists($field, $attributes)) {
             $attributes[$field] = boolval($attributes[$field]);
         }
     }
     return $attributes;
 }
开发者ID:vampirekiss,项目名称:lumen-restful-starter-kit,代码行数:18,代码来源:Model.php

示例15: attributesToArray

 /**
  * Convert the model's attributes to an array.
  *
  * @return array
  */
 public function attributesToArray()
 {
     $attributes = parent::attributesToArray();
     $attributes = $this->convertAttributes($attributes);
     return $attributes;
 }
开发者ID:MartinPham,项目名称:laravel-mongo,代码行数:11,代码来源:Model.php


注:本文中的Illuminate\Database\Eloquent\Model::attributesToArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。