'integer', 'target_id' => 'integer', 'meta' => 'array', 'created_at' => 'datetime', ]; // ── Event type constants ────────────────────────────────────────────────── const TYPE_UPLOAD = 'upload'; const TYPE_COMMENT = 'comment'; const TYPE_FAVORITE = 'favorite'; const TYPE_AWARD = 'award'; const TYPE_FOLLOW = 'follow'; const TARGET_ARTWORK = 'artwork'; const TARGET_USER = 'user'; // ── Relations ───────────────────────────────────────────────────────────── /** The user who performed the action */ public function actor(): BelongsTo { return $this->belongsTo(User::class, 'actor_id'); } // ── Factory helpers ─────────────────────────────────────────────────────── public static function record( int $actorId, string $type, string $targetType, int $targetId, array $meta = [] ): static { $event = static::create([ 'actor_id' => $actorId, 'type' => $type, 'target_type' => $targetType, 'target_id' => $targetId, 'meta' => $meta ?: null, 'created_at' => now(), ]); // Ensure created_at is available on the returned instance // ($timestamps = false means Eloquent doesn't auto-populate it) if ($event->created_at === null) { $event->created_at = now(); } return $event; } }