$properties */ #[Attributes\Identifiable('actl')] #[Guarded([ 'id', 'timestamp', ])] #[WithoutTimestamps] #[UseEloquentBuilder(ActivityLogBuilder::class)] class ActivityLog extends Model implements Identifiable { /** @use HasFactory */ use HasFactory; use HasRealtimeIdentifier; use MassPrunable; public const string RESOURCE_NAME = 'activity_log'; /** * Tracks all the events we no longer wish to display to users. These are either legacy * events or just events where we never ended up using the associated data. */ public const array DISABLED_EVENTS = ['server:file.upload']; protected $with = ['subjects']; /** * @return array */ protected function casts(): array { return [ 'properties' => 'collection', 'timestamp' => 'datetime', ]; } /** * @return MorphTo */ public function actor(): MorphTo { $morph = $this->morphTo(); if (method_exists($morph, 'withTrashed')) { // @phpstan-ignore function.alreadyNarrowedType return $morph->withTrashed(); } return $morph; } /** * @return HasMany */ public function subjects(): HasMany { return $this->hasMany(ActivityLogSubject::class); } /** * @return HasOne */ public function apiKey(): HasOne { return $this->hasOne(ApiKey::class, 'id', 'api_key_id'); } /** @return array */ public function propertyValues(): array { return $this->properties->all(); } /** * @return Builder */ public function prunable(): Builder { $days = config('activity.prune_days'); throw_unless($days > 0, LogicException::class, 'Cannot prune activity logs: no "prune_days" configuration value is set.'); return static::query()->where('timestamp', '<=', now()->subDays($days)); } protected static function boot(): void { parent::boot(); static::created(function (self $model): void { Event::dispatch(new ActivityLogged($model)); }); } }