Initial commit: Struktur aplikasi ilycats
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use App\Models\ActivityLog;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
trait LogsActivity
|
||||
{
|
||||
public function logAction($action, $modelInstance, $description)
|
||||
{
|
||||
if (Auth::check()) {
|
||||
// Pastikan model tidak null sebelum mengambil namanya
|
||||
$modelName = $modelInstance ? class_basename($modelInstance) : 'System';
|
||||
$modelId = $modelInstance ? ($modelInstance->id ?? null) : null;
|
||||
|
||||
ActivityLog::create([
|
||||
'user_id' => Auth::id(),
|
||||
'action' => $action,
|
||||
'model' => $modelName, // Sekarang tidak akan NULL
|
||||
'model_id' => $modelId,
|
||||
'description' => $description,
|
||||
'ip_address' => request()->ip(),
|
||||
// getChanges() hanya untuk update; saat delete kita kirim null atau data asli
|
||||
'properties' => ($modelInstance && method_exists($modelInstance, 'getChanges'))
|
||||
? $modelInstance->getChanges()
|
||||
: null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user