Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/advanced-usage/logging-model-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,20 @@ class NewsItem extends Model
}
```

Alternatively, you can use `$doNotRecordEvents` to exclude specific events while keeping all others.

```php
use Illuminate\Database\Eloquent\Model;
use Spatie\Activitylog\Traits\LogsActivity;

class NewsItem extends Model
{
use LogsActivity;

//the `created` event will not logged
protected static $doNotRecordEvents = ['created'];
}

## Customizing the description

By default the package will log `created`, `updated`, `deleted` in the description of the activity. You can modify this text by providing callback to the `->setDescriptionForEvent()` method on `LogOptions` class.
Expand Down
6 changes: 4 additions & 2 deletions src/Traits/LogsActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,10 @@ public function getLogNameToUse(): ?string
**/
protected static function eventsToBeRecorded(): Collection
{
$reject = collect(static::$doNotRecordEvents ?? []);

if (isset(static::$recordEvents)) {
return collect(static::$recordEvents);
return collect(static::$recordEvents)->reject(fn(string $eventName) => $reject->contains($eventName));
}

$events = collect([
Expand All @@ -159,7 +161,7 @@ protected static function eventsToBeRecorded(): Collection
$events->push('restored');
}

return $events;
return $events->reject(fn(string $eventName) => $reject->contains($eventName));
}

protected function shouldLogEvent(string $eventName): bool
Expand Down
Loading