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


PHP Model::isDirty方法代码示例

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


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

示例1: saving

 /**
  * Add the slug when not explicitly stated.
  *
  * @param  Model  $model
  * @return void
  */
 public function saving(Model $model)
 {
     $hasManuallyAssignedSlug = $model->slug && $model->isDirty('slug');
     if (!$model->isDirty('name') || $hasManuallyAssignedSlug) {
         return;
     }
     $slug = str_slug($model->getAttribute($this->fieldToSlug));
     $model->setAttribute($this->slugAttribute, $slug);
 }
开发者ID:salpakan,项目名称:salpakan,代码行数:15,代码来源:AddSlugAttribute.php

示例2: updated

 public function updated(Model $model)
 {
     if ($model->isDirty('parent_id')) {
         /**
          * 同步Original数据,是為了清除parent_id的dirty狀態
          */
         $model->syncOriginal();
         $tableName = $model->getTable();
         $oldNode = $model->getOriginal('node');
         if (0 < $model->parent_id) {
             /**
              * @var Model  $parent
              */
             $parent = $model->find($model->parent_id);
             $model->node = $parent->node . $model->id . self::SEPARATOR;
             $model->save();
             //取出原来的level
             $originalLevel = Cache::pull('node-category-original-level-' . $model->id);
             //计算新level与原来的level的差值
             $i = $model->level - $originalLevel;
             DB::table($tableName)->where('node', 'like', $oldNode . '%')->where('id', '<>', $model->id)->update(['level' => DB::raw("level + {$i}"), 'node' => DB::raw("REPLACE(`node`, '{$oldNode}', '{$model->node}')")]);
         } else {
             //修改為頂級分類
             $model->level = 1;
             $model->node = self::SEPARATOR . $model->id . self::SEPARATOR;
             $model->save();
             DB::table($tableName)->where('node', 'like', $oldNode . '%')->where('id', '<>', $model->id)->update(['level' => DB::raw("level - {$model->level}"), 'node' => DB::raw("CONCAT('{$model->node}', `id`, ',')")]);
         }
     }
 }
开发者ID:vergil-lai,项目名称:node-categoires,代码行数:30,代码来源:Observer.php

示例3: updating

 /**
  * Observe model saving for User.
  *
  * @param  \Illuminate\Database\Eloquent\Model  $model
  *
  * @return void
  */
 public function updating(Model $model)
 {
     $changes = [];
     $watchlist = (array) Arr::get($this->config, 'watchlist', []);
     foreach ($watchlist as $attribute) {
         if ($model->isDirty($attribute)) {
             $changes[$attribute] = $model->getAttribute($attribute);
         }
     }
     $recipient = new GenericRecipient($model->getOriginal('email'), $model->getRecipientName());
     $this->factory->notify($recipient, $model, $changes, $this->config);
 }
开发者ID:laravie,项目名称:warden,代码行数:19,代码来源:UserObserver.php

示例4: updated

 /**
  * On update, delete previous file if changed
  * 
  * @param  Model $model eloquent
  * @return mixed false or void
  */
 public function updated(Model $model)
 {
     if (!($attachments = $model->attachments)) {
         return;
     }
     foreach ($attachments as $fieldname) {
         // Nothing to do if file did not change
         if (!$model->isDirty($fieldname)) {
             continue;
         }
         $file = '/uploads/' . $model->getTable() . '/' . $model->getOriginal($fieldname);
         $this->delete($file);
     }
 }
开发者ID:Ayoubblog,项目名称:TypiCMS,代码行数:20,代码来源:FileObserver.php

示例5: isTranslationDirty

 /**
  * Checks if the translation is dirty
  *
  * @param Eloquent $translation
  * @return bool
  */
 protected function isTranslationDirty(Eloquent $translation)
 {
     return $translation->isDirty();
 }
开发者ID:NuclearCMS,项目名称:Hierarchy,代码行数:10,代码来源:Node.php

示例6: updated

 /**
  * On update, delete previous file if changed.
  *
  * @param Model $model eloquent
  *
  * @return mixed false or void
  */
 public function updated(Model $model)
 {
     if (!($attachments = $model->attachments)) {
         return;
     }
     foreach ($attachments as $fieldname) {
         // Nothing to do if file did not change
         if (!$model->isDirty($fieldname)) {
             continue;
         }
         $this->deleteFile($fieldname, $model);
     }
 }
开发者ID:eahrold,项目名称:Core,代码行数:20,代码来源:FileObserver.php

示例7: buildsSlug

 /**
  * The function that builds the slug.
  *
  * The slug field takes precedence over the name.
  *
  * @param  Model  $model - the Slug model
  *
  * @return string
  */
 public function buildsSlug(Model $model)
 {
     if ($model->isDirty($model->getSlugColumnKey())) {
         $column = $model->getSlugColumnKey();
     } else {
         $column = $model->getNameColumnKey();
     }
     return $this->slugify->slugify($model->getAttribute($column), array_get($this->config, 'slug_separator'));
 }
开发者ID:selfcomposer,项目名称:page-tree-manager,代码行数:18,代码来源:SlugService.php

示例8: isDirty

 /**
  * Determine if the model or given attribute(s) have been modified.
  *
  * @param  array|string|null $attributes
  * @return bool
  */
 public function isDirty($attributes = null)
 {
     return parent::isDirty($attributes) or $this->getSource()->isDirty($attributes);
 }
开发者ID:NuclearCMS,项目名称:Hierarchy,代码行数:10,代码来源:NodeSource.php

示例9: checkDirty

 protected function checkDirty(Model $model)
 {
     if ($model->isDirty()) {
         $this->changed++;
     }
 }
开发者ID:phaza,项目名称:laravel-norwegian-zip-codes,代码行数:6,代码来源:UpdateZipCodesCommand.php

示例10: updateTimestamps

 /**
  * Update the creation and update timestamps.
  *
  * @return void
  */
 protected function updateTimestamps(Model $model)
 {
     // Check if this model uses timestamps first.
     if (!$model->timestamps) {
         return;
     }
     $time = $model->freshTimestamp();
     if (!$model->isDirty(Model::UPDATED_AT)) {
         $model->setUpdatedAt($time);
     }
     if (!$model->exists && !$model->isDirty(Model::CREATED_AT)) {
         $model->setCreatedAt($time);
     }
 }
开发者ID:reverserob,项目名称:laravel-mongodb,代码行数:19,代码来源:EmbedsOneOrMany.php


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