27 خطوط
743 B
PHP
27 خطوط
743 B
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\ActivityLog;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class ActivityLogger
|
|
{
|
|
public static function log(string $action, ?string $description = null, ?Model $subject = null): void
|
|
{
|
|
try {
|
|
ActivityLog::create([
|
|
'user_id' => auth()->id(),
|
|
'action' => $action,
|
|
'description' => $description,
|
|
'subject_type' => $subject ? get_class($subject) : null,
|
|
'subject_id' => $subject?->id,
|
|
'ip_address' => request()->ip(),
|
|
'user_agent' => request()->userAgent(),
|
|
]);
|
|
} catch (\Exception $e) {
|
|
// Silent fail for logging
|
|
}
|
|
}
|
|
}
|