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


PHP Model::getDirty方法代码示例

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


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

示例1: updated

 /**
  * creates an activity entry for each dirty attribute
  * @param \Illuminate\Database\Eloquent\Model $model
  */
 public function updated($model)
 {
     $dirty = $model->getDirty();
     foreach ($dirty as $key => $value) {
         $data = ['type' => $key, 'note' => $value];
         $model->activity()->create($data);
     }
 }
开发者ID:absolux,项目名称:Collabor8-php-api,代码行数:12,代码来源:ActivityObserver.php

示例2: save

 public function save(Model $model)
 {
     if ($model->getDirty()) {
         return $model->save();
     } else {
         return $model->touch();
     }
 }
开发者ID:sdlyhu,项目名称:laravelio,代码行数:8,代码来源:EloquentRepository.php

示例3: record

 /**
  * Records differences between dirty and
  * clean attributes to the database.
  *
  * @param  Illuminate\Database\Eloquent\Model $model
  * @return boolean Whether there was a Changeset created
  */
 public function record(Model $model)
 {
     $dirty = $model->getDirty();
     // Remove dirty keys not in the auditable array
     if (isset($model->auditable) && is_array($model->auditable) && !in_array('*', $model->auditable)) {
         $dirty = array_intersect_key($dirty, array_flip($model->auditable));
     }
     if ($model->exists && count($dirty) > 0) {
         // Grab the models PK
         $primarykey = isset($model->primarykey) ? $model->primarykey : 'id';
         /*
          * -------------------------------------------------
          * Create the Changeset
          * -------------------------------------------------
          * We have to improvise a little here as we
          * don't want to depend on models having
          * relationships with the Auditable Changeset model.
          */
         $cs = new Changeset();
         $cs->object_type = get_class($model);
         // Manual
         $cs->object_id = $model->{$primarykey};
         // Manual
         $cs->user_id = \Auth::check() ? \Auth::user()->id : 0;
         $cs->save();
         // Add the Changeset changes
         foreach ($dirty as $k => $v) {
             $change = new Change();
             $change->key = $k;
             $change->old_value = $model->getOriginal($k);
             $change->new_value = $v;
             $cs->changes()->save($change);
         }
         return true;
     }
     return false;
 }
开发者ID:olsgreen,项目名称:laravel-auditable,代码行数:44,代码来源:Auditable.php

示例4: isTranslationDirty

 /**
  * @param \Illuminate\Database\Eloquent\Model $translation
  *
  * @return bool
  */
 protected function isTranslationDirty(Model $translation)
 {
     $dirtyAttributes = $translation->getDirty();
     unset($dirtyAttributes[$this->getLocaleKey()]);
     return count($dirtyAttributes) > 0;
 }
开发者ID:jooorooo,项目名称:multi-language,代码行数:11,代码来源:Translatable.php

示例5: getDirty

 /**
  * @override
  * Get the attributes that have been changed since last sync.
  *
  * @return array
  */
 public function getDirty()
 {
     $dirty = parent::getDirty();
     // We need to remove the primary key from the dirty attributes since primary keys
     // never change and when updating it shouldn't be part of the attributes.
     if (isset($dirty[$this->primaryKey])) {
         unset($dirty[$this->primaryKey]);
     }
     return $dirty;
 }
开发者ID:bobflay,项目名称:NeoEloquent,代码行数:16,代码来源:Model.php

示例6: 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

示例7: storeEloquentModel

 /**
  * Store/save current state of the model
  *
  * @param \Illuminate\Database\Eloquent\Model $model
  * @return mixed
  */
 protected function storeEloquentModel($model)
 {
     if ($model->getDirty()) {
         return $model->save();
     } else {
         return $model->touch();
     }
 }
开发者ID:pendopo,项目名称:anchor,代码行数:14,代码来源:EloquentRepository.php

示例8: getDirty

 /**
  * @return array
  */
 public function getDirty()
 {
     $dirty = parent::getDirty();
     $dirty['settings'] = json_encode($this->{$this->getSettingsProperty()});
     return $dirty;
 }
开发者ID:KodiComponents,项目名称:module-datasource,代码行数:9,代码来源:DatasourceModel.php

示例9: getAfter

 /**
  * Get the model's "after" snapshot.
  *
  * @return array
  */
 protected function getAfter()
 {
     $lookupTable = ['created' => $this->model->getAttributes(), 'updated' => $this->model->getDirty(), 'deleted' => null, 'soft-deleted' => ['deleted_at' => $this->model->{$this->model->getDeletedAtColumn()}], 'restored' => ['deleted_at' => $this->model->{$this->model->getDeletedAtColumn()}]];
     return collect($lookupTable)->get($this->getEvent());
 }
开发者ID:cklmercer,项目名称:laravel-model-time-machine,代码行数:10,代码来源:SnapShotFactory.php

示例10: getDirty

 /**
  * Override is dirty so we can trigger update if we have dirty images.
  * @return array
  */
 public function getDirty()
 {
     $dirty = parent::getDirty();
     if (!empty($this->files)) {
         // We just set the ID to the same value to trigger the update.
         $dirty[$this->getKeyName()] = $this->getKey();
     }
     return $dirty;
 }
开发者ID:despark,项目名称:ignicms,代码行数:13,代码来源:AdminModel.php

示例11: isTranslationDirty

 /**
  * @param \Illuminate\Database\Eloquent\Model $translation
  *
  * @return bool
  */
 protected function isTranslationDirty(Model $translation)
 {
     $dirtyAttributes = $translation->getDirty();
     return count($dirtyAttributes) > 0;
 }
开发者ID:administrcms,项目名称:localization,代码行数:10,代码来源:Translatable.php


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