You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have in my model a number of appended attributes, and I have also added them into the dontVersionFields array. However, it didn't seem to work at all.
The text was updated successfully, but these errors were encountered:
Temporarily disable the appends before versioning, and then put back post version.
classExampleextendsModel
{
useVersionableTrait {
VersionableTrait::versionablePreSave as traitVersionablePreSave;
VersionableTrait::versionablePostSave as traitVersionablePostSave;
}
protected$appends = [
'exampleAppend',
'anotherExample'
];
// used to temporarily store $appendsprotected$originalAppends = null;
/** * Versionable trait post model save. * * Temporarily remove appends before versioning as we don't want to version the append content, * and dontVersionFields does not seem to work properly on appended attributes * see https://github.com/mpociot/versionable/issues/85 * * @return void */protectedfunctionversionablePreSave()
{
// keep track of original appends$this->originalAppends = $this->appends;
// clear appends so we don't version ammend values$this->setAppends([]);
// call original pre-save trait to the before versioning stuff$this->traitVersionablePreSave();
}
/** * Versionable trait post model save * * @return void */protectedfunctionversionablePostSave()
{
// call original post save trait to create new version$this->traitVersionablePostSave();
// set the original appends back after versioning (as it was disabled in versionablePreSave)$this->setAppends($this->originalAppends);
}
}
I have in my model a number of appended attributes, and I have also added them into the dontVersionFields array. However, it didn't seem to work at all.
The text was updated successfully, but these errors were encountered: