initial commit
This commit is contained in:
@@ -1,15 +1,19 @@
|
||||
<?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()
|
||||
trait HasPermissions
|
||||
{
|
||||
public function hasPermission($moduleSlug, $action): bool
|
||||
{
|
||||
if ($this->getRawOriginal('role') === 'admin') {
|
||||
return true;
|
||||
}
|
||||
$role = $this->roleModel;
|
||||
if (!$role) return false;
|
||||
$column = str_starts_with($action, 'can_') ? $action : 'can_' . $action;
|
||||
return $role->permissions()
|
||||
->where('module_slug', $moduleSlug)
|
||||
->where($action, 1)
|
||||
->where($column, 1)
|
||||
->exists();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user