summaryrefslogtreecommitdiff
path: root/app/Models/ActivityLog.php
diff options
context:
space:
mode:
authorgrothedev <grothedev@gmail.com>2025-12-28 22:16:11 -0500
committergrothedev <grothedev@gmail.com>2025-12-28 22:16:11 -0500
commit57445d4ccbfe1cb190437c8f6b609fc83723b015 (patch)
tree2e4f50e834faceb068502d231ad2c9cc30067f9b /app/Models/ActivityLog.php
had claude code start making this project just to see what happens
Diffstat (limited to 'app/Models/ActivityLog.php')
-rw-r--r--app/Models/ActivityLog.php46
1 files changed, 46 insertions, 0 deletions
diff --git a/app/Models/ActivityLog.php b/app/Models/ActivityLog.php
new file mode 100644
index 0000000..7c7e31c
--- /dev/null
+++ b/app/Models/ActivityLog.php
@@ -0,0 +1,46 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+class ActivityLog extends Model
+{
+ const UPDATED_AT = null; // Activity logs are append-only, no updates
+
+ protected $fillable = [
+ 'loggable_id',
+ 'loggable_type',
+ 'event_type',
+ 'ip_address',
+ 'user_agent',
+ 'data',
+ ];
+
+ protected $casts = [
+ 'data' => 'array',
+ 'created_at' => 'datetime',
+ ];
+
+ // Polymorphic relationship
+ public function loggable()
+ {
+ return $this->morphTo();
+ }
+
+ // Scopes
+ public function scopeForEvent($query, string $eventType)
+ {
+ return $query->where('event_type', $eventType);
+ }
+
+ public function scopeByIp($query, string $ip)
+ {
+ return $query->where('ip_address', $ip);
+ }
+
+ public function scopeRecent($query, $hours = 24)
+ {
+ return $query->where('created_at', '>=', now()->subHours($hours));
+ }
+}