Skip to content

Commit 7d929c0

Browse files
Merge pull request #850 from s4muel/master
allow selecting columns to be saved when using auditDetach(), auditSync() and auditSyncWithoutDetaching()
2 parents 5b217a7 + dcb1a6b commit 7d929c0

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/Auditable.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ public function auditAttach(string $relationName, $id, array $attributes = [], $
675675
* @return int
676676
* @throws AuditingException
677677
*/
678-
public function auditDetach(string $relationName, $ids = null, $touch = true)
678+
public function auditDetach(string $relationName, $ids = null, $touch = true, $columns = ['*'])
679679
{
680680
if (!method_exists($this, $relationName) || !method_exists($this->{$relationName}(), 'detach')) {
681681
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)
684684
$this->auditEvent = 'detach';
685685
$this->isCustomEvent = true;
686686
$this->auditCustomOld = [
687-
$relationName => $this->{$relationName}()->get()->toArray()
687+
$relationName => $this->{$relationName}()->get($columns)->toArray()
688688
];
689689
$results = $this->{$relationName}()->detach($ids, $touch);
690690
$this->auditCustomNew = [
691-
$relationName => $this->{$relationName}()->get()->toArray()
691+
$relationName => $this->{$relationName}()->get($columns)->toArray()
692692
];
693693
Event::dispatch(AuditCustom::class, [$this]);
694694
$this->isCustomEvent = false;
@@ -703,7 +703,7 @@ public function auditDetach(string $relationName, $ids = null, $touch = true)
703703
* @return array
704704
* @throws AuditingException
705705
*/
706-
public function auditSync($relationName, $ids, $detaching = true)
706+
public function auditSync($relationName, $ids, $detaching = true, $columns = ['*'])
707707
{
708708
if (!method_exists($this, $relationName) || !method_exists($this->{$relationName}(), 'sync')) {
709709
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)
712712
$this->auditEvent = 'sync';
713713

714714
$this->auditCustomOld = [
715-
$relationName => $this->{$relationName}()->get()->toArray()
715+
$relationName => $this->{$relationName}()->get($columns)->toArray()
716716
];
717717

718718
$changes = $this->{$relationName}()->sync($ids, $detaching);
@@ -722,7 +722,7 @@ public function auditSync($relationName, $ids, $detaching = true)
722722
$this->auditCustomNew = [];
723723
} else {
724724
$this->auditCustomNew = [
725-
$relationName => $this->{$relationName}()->get()->toArray()
725+
$relationName => $this->{$relationName}()->get($columns)->toArray()
726726
];
727727
}
728728

@@ -740,11 +740,11 @@ public function auditSync($relationName, $ids, $detaching = true)
740740
* @return array
741741
* @throws AuditingException
742742
*/
743-
public function auditSyncWithoutDetaching(string $relationName, $ids)
743+
public function auditSyncWithoutDetaching(string $relationName, $ids, $columns = ['*'])
744744
{
745745
if (!method_exists($this, $relationName) || !method_exists($this->{$relationName}(), 'syncWithoutDetaching')) {
746746
throw new AuditingException('Relationship ' . $relationName . ' was not found or does not support method syncWithoutDetaching');
747747
}
748-
return $this->auditSync($relationName, $ids, false);
748+
return $this->auditSync($relationName, $ids, false, $columns);
749749
}
750750
}

0 commit comments

Comments
 (0)