本文整理汇总了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);
}
}
示例2: save
public function save(Model $model)
{
if ($model->getDirty()) {
return $model->save();
} else {
return $model->touch();
}
}
示例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;
}
示例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;
}
示例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;
}
示例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');
}
示例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();
}
}
示例8: getDirty
/**
* @return array
*/
public function getDirty()
{
$dirty = parent::getDirty();
$dirty['settings'] = json_encode($this->{$this->getSettingsProperty()});
return $dirty;
}
示例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());
}
示例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;
}
示例11: isTranslationDirty
/**
* @param \Illuminate\Database\Eloquent\Model $translation
*
* @return bool
*/
protected function isTranslationDirty(Model $translation)
{
$dirtyAttributes = $translation->getDirty();
return count($dirtyAttributes) > 0;
}