-
Notifications
You must be signed in to change notification settings - Fork 350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I get an error when trying to update my user model when using the RevisionableTrait #436
Comments
As a side-note, here is the part of the RevisionableTrait that is causing the error: public function postSave()
{
if (isset($this->historyLimit) && $this->revisionHistory()->count() >= $this->historyLimit) {
$LimitReached = true;
} else {
$LimitReached = false;
}
if (isset($this->revisionCleanup)){
$RevisionCleanup=$this->revisionCleanup;
}else{
$RevisionCleanup=false;
}
// check if the model already exists
if (((!isset($this->revisionEnabled) || $this->revisionEnabled) && $this->updating) && (!$LimitReached || $RevisionCleanup)) {
// if it does, it means we're updating
$changes_to_record = $this->changedRevisionableFields();
$revisions = array();
foreach ($changes_to_record as $key => $change) {
$original = array(
'revisionable_type' => $this->getMorphClass(),
'revisionable_id' => $this->getKey(),
'key' => $key,
'old_value' => Arr::get($this->originalData, $key),
'new_value' => $this->updatedData[$key],
'user_id' => $this->getSystemUserId(),
'created_at' => new \DateTime(),
'updated_at' => new \DateTime(),
);
$revisions[] = array_merge($original, $this->getAdditionalFields());
}
if (count($revisions) > 0) {
if($LimitReached && $RevisionCleanup){
$toDelete = $this->revisionHistory()->orderBy('id','asc')->limit(count($revisions))->get();
foreach($toDelete as $delete){
$delete->delete();
}
}
$revision = Revisionable::newModel();
\DB::table($revision->getTable())->insert($revisions);
\Event::dispatch('revisionable.saved', array('model' => $this, 'revisions' => $revisions));
}
}
} All the way at the bottom, the \Event::dispatch('revisionable.saved', array('model' => $this, 'revisions' => $revisions)); Is where it goes wrong |
Remove the use Illuminate\Support\Facades\Event; I hope this helps! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Relevant part of the user model:
Error I get from RevisionableTrait when trying to update anything on any user:
Somehow the event function is broken. I haven't dug too deep into the code, but I don't really have any time to do so.
The text was updated successfully, but these errors were encountered: