them log, chinh upload
This commit is contained in:
27
app/Services/ActivityLogger.php
Normal file
27
app/Services/ActivityLogger.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\ActivityLog;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ActivityLogger
|
||||
{
|
||||
public static function log(
|
||||
string $action,
|
||||
string $description,
|
||||
?Model $subject = null,
|
||||
?array $metadata = null,
|
||||
?int $userId = null,
|
||||
): ActivityLog {
|
||||
return ActivityLog::create([
|
||||
'user_id' => $userId ?? auth()->id(),
|
||||
'action' => $action,
|
||||
'description' => $description,
|
||||
'subject_type' => $subject ? get_class($subject) : null,
|
||||
'subject_id' => $subject?->id,
|
||||
'metadata' => $metadata,
|
||||
'created_at' => now(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user