Skip to content

Commit

Permalink
allow selecting columns to be saved when using auditAttach() method
Browse files Browse the repository at this point in the history
  • Loading branch information
s4muel committed Aug 17, 2023
1 parent 8b9c5bd commit 43fbbe6
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 43fbbe6

Please sign in to comment.