Files
ilycats/app/Traits/HasPermissions.php
T

20 lines
509 B
PHP
Raw Normal View History

2026-02-08 15:16:35 +07:00
<?php
namespace App\Traits;
2026-09-23 12:45:02 +07:00
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()
2026-02-08 15:16:35 +07:00
->where('module_slug', $moduleSlug)
2026-09-23 12:45:02 +07:00
->where($column, 1)
2026-02-08 15:16:35 +07:00
->exists();
}
2026-09-23 12:45:02 +07:00
}