本文整理汇总了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);
}
示例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`, ',')")]);
}
}
}
示例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);
}
示例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);
}
}
示例5: isTranslationDirty
/**
* Checks if the translation is dirty
*
* @param Eloquent $translation
* @return bool
*/
protected function isTranslationDirty(Eloquent $translation)
{
return $translation->isDirty();
}
示例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);
}
}
示例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'));
}
示例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);
}
示例9: checkDirty
protected function checkDirty(Model $model)
{
if ($model->isDirty()) {
$this->changed++;
}
}
示例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);
}
}