'array', 'new_values' => 'array', 'created_at' => 'datetime', ]; // ── Relationships ── public function user() { return $this->belongsTo(User::class); } public function actor() { return $this->belongsTo(User::class, 'actor_id'); } // ── Scopes ── public function scopeForUser($query, int $userId) { return $query->where('user_id', $userId); } public function scopeForAction($query, string $action) { return $query->where('action', $action); } public function scopeRecent($query, int $hours = 24) { return $query->where('created_at', '>=', now()->subHours($hours)); } // ── Static factory ── /** * Log an audit event. Called by the AuditService. */ public static function record(array $data): self { return self::create(array_merge($data, [ 'created_at' => now(), ])); } }