當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。