Files
ilycats/app/Traits/HasPermissions.php
T
2026-09-23 12:45:02 +07:00

20 lines
509 B
PHP

<?php
namespace App\Traits;
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($column, 1)
->exists();
}
}