'array', 'created_at' => 'datetime', ]; // Event types const EVENT_JOB_VIEW = 'job_view'; const EVENT_JOB_APPLY_CLICK = 'job_apply_click'; const EVENT_SEARCH = 'search'; const EVENT_FILTER = 'filter'; const EVENT_CATEGORY_VIEW = 'category_view'; public function job(): BelongsTo { return $this->belongsTo(Job::class); } /** * Scope to get events by type */ public function scopeOfType($query, string $type) { return $query->where('event_type', $type); } /** * Scope to get events within a date range */ public function scopeWithinDays($query, int $days) { return $query->where('created_at', '>=', now()->subDays($days)); } /** * Log an event */ public static function logEvent(string $eventType, ?int $jobId = null, array $eventData = []): void { self::create([ 'event_type' => $eventType, 'job_id' => $jobId, 'session_id' => session()->getId(), 'ip_address' => request()->ip(), 'user_agent' => request()->userAgent(), 'referer' => request()->header('referer'), 'event_data' => $eventData, ]); } }