diff --git a/src/Auditable.php b/src/Auditable.php index e35c2cab..ce6bb889 100644 --- a/src/Auditable.php +++ b/src/Auditable.php @@ -675,7 +675,7 @@ public function auditAttach(string $relationName, $id, array $attributes = [], $ * @return int * @throws AuditingException */ - public function auditDetach(string $relationName, $ids = null, $touch = true) + public function auditDetach(string $relationName, $ids = null, $touch = true, $columns = ['*']) { if (!method_exists($this, $relationName) || !method_exists($this->{$relationName}(), 'detach')) { throw new AuditingException('Relationship ' . $relationName . ' was not found or does not support method detach'); @@ -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()->toArray() + $relationName => $this->{$relationName}()->get($columns)->toArray() ]; $results = $this->{$relationName}()->detach($ids, $touch); $this->auditCustomNew = [ - $relationName => $this->{$relationName}()->get()->toArray() + $relationName => $this->{$relationName}()->get($columns)->toArray() ]; Event::dispatch(AuditCustom::class, [$this]); $this->isCustomEvent = false; @@ -703,7 +703,7 @@ public function auditDetach(string $relationName, $ids = null, $touch = true) * @return array * @throws AuditingException */ - public function auditSync($relationName, $ids, $detaching = true) + public function auditSync($relationName, $ids, $detaching = true, $columns = ['*']) { if (!method_exists($this, $relationName) || !method_exists($this->{$relationName}(), 'sync')) { throw new AuditingException('Relationship ' . $relationName . ' was not found or does not support method sync'); @@ -712,7 +712,7 @@ public function auditSync($relationName, $ids, $detaching = true) $this->auditEvent = 'sync'; $this->auditCustomOld = [ - $relationName => $this->{$relationName}()->get()->toArray() + $relationName => $this->{$relationName}()->get($columns)->toArray() ]; $changes = $this->{$relationName}()->sync($ids, $detaching); @@ -722,7 +722,7 @@ public function auditSync($relationName, $ids, $detaching = true) $this->auditCustomNew = []; } else { $this->auditCustomNew = [ - $relationName => $this->{$relationName}()->get()->toArray() + $relationName => $this->{$relationName}()->get($columns)->toArray() ]; } @@ -740,11 +740,11 @@ public function auditSync($relationName, $ids, $detaching = true) * @return array * @throws AuditingException */ - public function auditSyncWithoutDetaching(string $relationName, $ids) + public function auditSyncWithoutDetaching(string $relationName, $ids, $columns = ['*']) { if (!method_exists($this, $relationName) || !method_exists($this->{$relationName}(), 'syncWithoutDetaching')) { throw new AuditingException('Relationship ' . $relationName . ' was not found or does not support method syncWithoutDetaching'); } - return $this->auditSync($relationName, $ids, false); + return $this->auditSync($relationName, $ids, false, $columns); } }