'array', 'created_at' => 'datetime', ]; } public function user(): BelongsTo { return $this->belongsTo(User::class)->withTrashed(); } public static function log( string $action, string $description, ?string $modelType = null, ?int $modelId = null, ?array $properties = null, ): self { $log = new static(); $log->user_id = auth()->id(); $log->action = $action; $log->model_type = $modelType; $log->model_id = $modelId; $log->description = $description; $log->properties = $properties; $log->ip_address = request()->ip(); $log->created_at = now(); $log->save(); return $log; } public static function logWithChanges( string $action, string $description, ?string $modelType = null, ?int $modelId = null, ?array $old = null, ?array $new = null, ): self { $properties = null; if ($old !== null || $new !== null) { $properties = array_filter(['old' => $old, 'new' => $new], fn ($v) => $v !== null); } return static::log($action, $description, $modelType, $modelId, $properties ?: null); } }