first&last
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\ActivityLog;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ActivityLogService
|
||||
{
|
||||
public function log(
|
||||
?User $user,
|
||||
Model|string $model,
|
||||
int|string|null $modelId,
|
||||
string $action,
|
||||
string $description,
|
||||
?string $ipAddress = null
|
||||
): ActivityLog {
|
||||
if ($model instanceof Model) {
|
||||
$modelClass = $model::class;
|
||||
$modelId = $model->getKey();
|
||||
} else {
|
||||
$modelClass = $model;
|
||||
}
|
||||
|
||||
return ActivityLog::query()->create([
|
||||
'user_id' => $user?->id,
|
||||
'model_type' => $modelClass,
|
||||
'model_id' => $modelId ?? 0,
|
||||
'action' => $action,
|
||||
'description' => $description,
|
||||
'ip_address' => $ipAddress,
|
||||
'created_at' => now(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user