25 lines
671 B
PHP
25 lines
671 B
PHP
<?php
|
|
|
|
namespace App\Services\Audit;
|
|
|
|
use App\Models\AuditLog;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Facades\Request;
|
|
|
|
class AuditLogger
|
|
{
|
|
public function log(User $actor, string $action, ?Model $auditable = null, array $metadata = []): AuditLog
|
|
{
|
|
return AuditLog::create([
|
|
'user_id' => $actor->id,
|
|
'action' => $action,
|
|
'auditable_type' => $auditable?->getMorphClass(),
|
|
'auditable_id' => $auditable?->getKey(),
|
|
'ip_address' => Request::ip(),
|
|
'user_agent' => Request::userAgent(),
|
|
'metadata' => $metadata,
|
|
]);
|
|
}
|
|
}
|