Initial commit: Struktur aplikasi ilycats
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
namespace App\Traits;
|
||||
|
||||
trait HasPermissions {
|
||||
public function hasPermission($moduleSlug, $action) {
|
||||
// Jika user tidak punya role, akses ditolak
|
||||
if (!$this->role) return false;
|
||||
|
||||
// Cek ke tabel permission_role
|
||||
return $this->role->permissions()
|
||||
->where('module_slug', $moduleSlug)
|
||||
->where($action, 1)
|
||||
->exists();
|
||||
}
|
||||
}
|
||||
@@ -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