Skip to content

Commit

Permalink
Merge pull request #844 from s4muel/s4muel-patch-1
Browse files Browse the repository at this point in the history
allow selecting columns to be saved when using auditAttach() method
  • Loading branch information
MortenDHansen authored Aug 24, 2023
2 parents 6421f6a + 43fbbe6 commit 5b217a7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Auditable.php
Original file line number Diff line number Diff line change
Expand Up @@ -650,19 +650,19 @@ public function transitionTo(Contracts\Audit $audit, bool $old = false): Contrac
* @return void
* @throws AuditingException
*/
public function auditAttach(string $relationName, $id, array $attributes = [], $touch = true, $columns = ['name'])
public function auditAttach(string $relationName, $id, array $attributes = [], $touch = true, $columns = ['*'])
{
if (!method_exists($this, $relationName) || !method_exists($this->{$relationName}(), 'attach')) {
throw new AuditingException('Relationship ' . $relationName . ' was not found or does not support method attach');
}
$this->auditEvent = 'attach';
$this->isCustomEvent = true;
$this->auditCustomOld = [
$relationName => $this->{$relationName}()->get()->toArray()
$relationName => $this->{$relationName}()->get($columns)->toArray()
];
$this->{$relationName}()->attach($id, $attributes, $touch);
$this->auditCustomNew = [
$relationName => $this->{$relationName}()->get()->toArray()
$relationName => $this->{$relationName}()->get($columns)->toArray()
];
Event::dispatch(AuditCustom::class, [$this]);
$this->isCustomEvent = false;
Expand Down

0 comments on commit 5b217a7

Please sign in to comment.