Skip to content

Commit

Permalink
Don't need to execute these calls multiple times (#831)
Browse files Browse the repository at this point in the history
  • Loading branch information
gms8994 committed Jun 19, 2023
1 parent 36e61e5 commit 8b9c5bd
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Auditable.php
Expand Up @@ -658,11 +658,11 @@ public function auditAttach(string $relationName, $id, array $attributes = [], $
$this->auditEvent = 'attach';
$this->isCustomEvent = true;
$this->auditCustomOld = [
$relationName => $this->{$relationName}()->get()->isEmpty() ? [] : $this->{$relationName}()->get()->toArray()
$relationName => $this->{$relationName}()->get()->toArray()
];
$this->{$relationName}()->attach($id, $attributes, $touch);
$this->auditCustomNew = [
$relationName => $this->{$relationName}()->get()->isEmpty() ? [] : $this->{$relationName}()->get()->toArray()
$relationName => $this->{$relationName}()->get()->toArray()
];
Event::dispatch(AuditCustom::class, [$this]);
$this->isCustomEvent = false;
Expand All @@ -684,11 +684,11 @@ public function auditDetach(string $relationName, $ids = null, $touch = true)
$this->auditEvent = 'detach';
$this->isCustomEvent = true;
$this->auditCustomOld = [
$relationName => $this->{$relationName}()->get()->isEmpty() ? [] : $this->{$relationName}()->get()->toArray()
$relationName => $this->{$relationName}()->get()->toArray()
];
$results = $this->{$relationName}()->detach($ids, $touch);
$this->auditCustomNew = [
$relationName => $this->{$relationName}()->get()->isEmpty() ? [] : $this->{$relationName}()->get()->toArray()
$relationName => $this->{$relationName}()->get()->toArray()
];
Event::dispatch(AuditCustom::class, [$this]);
$this->isCustomEvent = false;
Expand All @@ -712,7 +712,7 @@ public function auditSync($relationName, $ids, $detaching = true)
$this->auditEvent = 'sync';

$this->auditCustomOld = [
$relationName => $this->{$relationName}()->get()->isEmpty() ? [] : $this->{$relationName}()->get()->toArray()
$relationName => $this->{$relationName}()->get()->toArray()
];

$changes = $this->{$relationName}()->sync($ids, $detaching);
Expand All @@ -722,7 +722,7 @@ public function auditSync($relationName, $ids, $detaching = true)
$this->auditCustomNew = [];
} else {
$this->auditCustomNew = [
$relationName => $this->{$relationName}()->get()->isEmpty() ? [] : $this->{$relationName}()->get()->toArray()
$relationName => $this->{$relationName}()->get()->toArray()
];
}

Expand Down

0 comments on commit 8b9c5bd

Please sign in to comment.