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


PHP Model::getAttributes方法代码示例

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


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

示例1: performUpdate

 /**
  * Save an existing model and attach it to the parent model.
  *
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @return Model|bool
  */
 protected function performUpdate(Model $model)
 {
     $result = $this->query->update(array($this->localKey => $model->getAttributes()));
     if ($result) {
         $this->associate($model);
     }
     return $result ? $model : false;
 }
开发者ID:reverserob,项目名称:laravel-mongodb,代码行数:14,代码来源:EmbedsOne.php

示例2: castModel

 /**
  * Get an array representing the properties of a model.
  *
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @return array
  */
 public static function castModel(Model $model)
 {
     $attributes = array_merge($model->getAttributes(), $model->getRelations());
     $visible = array_flip($model->getVisible() ?: array_diff(array_keys($attributes), $model->getHidden()));
     $results = [];
     foreach (array_intersect_key($attributes, $visible) as $key => $value) {
         $results[(isset($visible[$key]) ? Caster::PREFIX_VIRTUAL : Caster::PREFIX_PROTECTED) . $key] = $value;
     }
     return $results;
 }
开发者ID:EnmanuelCode,项目名称:backend-laravel,代码行数:16,代码来源:IlluminateCaster.php

示例3: newFromEloquentModel

 /**
  * Build new instance from an eloquent model object.
  *
  * @param \Illuminate\Database\Eloquent\Model $eloquentModel
  * @param array $name
  * @return \ProAI\Datamapper\Support\ValueObject
  */
 public static function newFromEloquentModel(EloquentModel $eloquentModel, $name)
 {
     $valueObject = new static();
     // get model data
     $dict = ['mapping' => $eloquentModel->getMapping(), 'attributes' => $eloquentModel->getAttributes()];
     foreach ($dict['mapping']['embeddeds'][$name]['attributes'] as $attribute => $column) {
         $valueObject->{$attribute} = $dict['attributes'][$column];
     }
     return $valueObject;
 }
开发者ID:emtudo,项目名称:laravel-datamapper,代码行数:17,代码来源:ValueObject.php

示例4: assertModelPatched

 /**
  * Assert that a model has been patched.
  *
  * @param Model $model
  *      the model before it was patched.
  * @param array $changedAttributes
  *      the expected changed attributes - key to value pairs.
  * @param string|string[] $unchangedKeys
  *      the keys of the attributes that should not have changed.
  * @return $this
  */
 protected function assertModelPatched(Model $model, array $changedAttributes, $unchangedKeys = [])
 {
     /** We need to ensure values are cast to database values */
     $expected = $model->newInstance($changedAttributes)->getAttributes();
     $attributes = $model->getAttributes();
     foreach ((array) $unchangedKeys as $attr) {
         $expected[$attr] = isset($attributes[$attr]) ? $attributes[$attr] : null;
     }
     $expected[$model->getKeyName()] = $model->getKey();
     return $this->seeModelInDatabase($model, $expected);
 }
开发者ID:cloudcreativity,项目名称:laravel-json-api,代码行数:22,代码来源:InteractsWithModels.php

示例5: newFromEloquentObject

 /**
  * Build new instance from an eloquent model object.
  *
  * @param \Illuminate\Database\Eloquent\Model $eloquentModel
  * @param array $name
  * @return \ProAI\Datamapper\Support\ValueObject
  */
 public static function newFromEloquentObject(EloquentModel $eloquentModel, $name)
 {
     $rc = new ReflectionClass(static::class);
     $valueObject = $rc->newInstanceWithoutConstructor();
     // get model data
     $dict = ['mapping' => $eloquentModel->getMapping(), 'attributes' => $eloquentModel->getAttributes()];
     foreach ($dict['mapping']['embeddeds'][$name]['attributes'] as $attribute => $column) {
         $valueObject->{$attribute} = $dict['attributes'][$column];
     }
     return $valueObject;
 }
开发者ID:proai,项目名称:laravel-datamapper,代码行数:18,代码来源:ValueObject.php

示例6: validate

 /**
  * Validate the given model.
  *
  * @param \Illuminate\Database\Eloquent\Model $model
  *
  * @throws \AltThree\Validator\ValidationException
  *
  * @return void
  */
 protected function validate(Model $model)
 {
     $attributes = $model->getAttributes();
     $messages = isset($model->validationMessages) ? $model->validationMessages : [];
     $validator = $this->factory->make($attributes, $model->rules, $messages);
     if ($validator->fails()) {
         throw new ValidationException($validator->getMessageBag());
     }
     if (method_exists($model, 'validate')) {
         $model->validate();
     }
 }
开发者ID:AltThree,项目名称:Validator,代码行数:21,代码来源:ValidatingObserver.php

示例7: save

 /**
  * Save data to repository table
  *
  * @param Model $model
  * @param string $changeType
  */
 private function save(Model $model, $changeType)
 {
     $rc = new \ReflectionClass($model);
     $class = $rc->getShortName();
     $namespace = $rc->getNamespaceName();
     $repositoryClass = $namespace . '\\Repository' . $class;
     $repository = new $repositoryClass();
     $repository->{str_singular($model->getTable()) . '_id'} = $model->id;
     $repository->type = $changeType;
     $repository->data = $model->getAttributes();
     if (\Config::get('dbrepository.save_user') === true && \Auth::check()) {
         $repository->changed_by = \Auth::user()->id;
     }
     $repository->save();
 }
开发者ID:wilgucki,项目名称:dbrepository,代码行数:21,代码来源:DbRepositoryListener.php

示例8: diff

 /**
  * @param Model $left
  * @param Model $right
  * @param array $ignoredFields additional fields to ignore in the diff
  *
  * @return array
  * @throws IncompatibleModelMismatchException
  */
 public function diff(Model $left, Model $right, $ignoredFields = [])
 {
     if ($left instanceof $right === false) {
         throw new IncompatibleModelMismatchException();
     }
     $ignoredFields = array_merge($this->ignoredFields, $ignoredFields);
     $changes = [];
     $leftAttributes = array_except($left->getAttributes(), $ignoredFields);
     $rightAttributes = array_except($right->getAttributes(), $ignoredFields);
     $differences = array_diff($leftAttributes, $rightAttributes);
     foreach ($differences as $key => $value) {
         $changes[$key][0] = $leftAttributes[$key];
         $changes[$key][1] = $rightAttributes[$key];
         $changes[$key]['left'] = $leftAttributes[$key];
         $changes[$key]['right'] = $rightAttributes[$key];
     }
     return $changes;
 }
开发者ID:sbarre,项目名称:eloquent-versioned,代码行数:26,代码来源:VersionDiffer.php

示例9: update

 /**
  * POST: Update|Edit /{id}.
  */
 public function update()
 {
     return DB::transaction(function () {
         // Carregar ID
         $id = $this->getRouteId();
         // Carregar model
         $this->model = $this->model->find($id);
         // Criar serviço
         $service = $this->getService();
         // Validar
         $rules = $this->validatesUpdate;
         if (is_array($rules) && count($rules) > 0) {
             $data = array_merge([], $this->model->getAttributes(), $this->request->all());
             $params = ['table' => $this->model->getTable(), 'id' => $id];
             $service->validate($data, $rules, $params, $this->references);
         }
         // Executar
         $return = $service->update($this->model, $this->request, $this->references);
         return $return;
     });
 }
开发者ID:bugotech,项目名称:http,代码行数:24,代码来源:ResourceController.php

示例10: associate

 /**
  * Attach the model to its parent.
  *
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @return \Illuminate\Database\Eloquent\Model
  */
 public function associate(Model $model)
 {
     return $this->setEmbedded($model->getAttributes());
 }
开发者ID:rohmad-st,项目名称:laravel-mongodb,代码行数:10,代码来源:EmbedsOne.php

示例11: prepareDataAndRules

	/**
	 * Sets the proper data attributes and rules arrays depending on whether or not the model exists
	 *
	 * @param \Illuminate\Database\Eloquent\Model	$model
	 *
	 * @return array	//'data' and 'rules' indexes both arrays
	 */
	public function prepareDataAndRules($model)
	{
		//fetch the rules if any exist
		$rules = $this->getModelValidationRules();

		//if the model exists, this is an update
		if ($model->exists)
		{
			//only include dirty fields
			$data = $model->getDirty();

			//and validate the fields that are being updated
			$rules = array_intersect_key($rules, $data);
		}
		else
		{
			//otherwise validate everything
			$data = $model->getAttributes();
		}

		return compact('data', 'rules');
	}
开发者ID:pcerbino,项目名称:falcionevega,代码行数:29,代码来源:Config.php

示例12: associateExisting

 /**
  * Associate an existing model instance to the given parent, without saving it to the database.
  *
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @return \Illuminate\Database\Eloquent\Model
  */
 protected function associateExisting($model)
 {
     // Get existing embedded documents.
     $records = $this->getEmbedded();
     $primaryKey = $this->related->getKeyName();
     $key = $model->getKey();
     // Replace the document in the parent model.
     foreach ($records as &$record) {
         if ($record[$primaryKey] == $key) {
             $record = $model->getAttributes();
             break;
         }
     }
     return $this->setEmbedded($records);
 }
开发者ID:errietta,项目名称:laravel-mongodb,代码行数:21,代码来源:EmbedsMany.php

示例13: getIndexableAttributes

 /**
  * Return an array of attributes to be indexed.
  *
  * @param Model $model
  * @return array
  */
 public function getIndexableAttributes(Model $model)
 {
     return $model->getAttributes();
 }
开发者ID:michaeljennings,项目名称:laralastica,代码行数:10,代码来源:Searchable.php

示例14: getAllAttributes

 public function getAllAttributes()
 {
     return parent::getAttributes();
 }
开发者ID:albafo,项目名称:web.MagickLaravel,代码行数:4,代码来源:MagickEloquent.php

示例15: created

 public function created(Eloquent $object)
 {
     $object->logs()->create(['type' => Model::CREATE, 'data' => $object->getAttributes()]);
 }
开发者ID:dkulyk,项目名称:eloquent-extra,代码行数:4,代码来源:Listener.php


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