Files
2026-09-30 16:27:32 +02:00

32 lines
851 B
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class AuditLog extends Model
{
public const UPDATED_AT = null;
protected $guarded = ['id'];
protected function casts(): array
{
return ['changes' => 'array'];
}
public static function record(string $actorType, ?string $actor, string $action, ?Model $subject = null, array $changes = [], ?int $tenantId = null): self
{
return static::create([
'tenant_id' => $tenantId ?? ($subject?->tenant_id ?? null),
'actor_type' => $actorType,
'actor' => $actor,
'action' => $action,
'subject_type' => $subject ? $subject::class : null,
'subject_id' => $subject?->getKey(),
'changes' => $changes ?: null,
'ip' => request()?->ip(),
]);
}
}