45
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<?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(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user