# [Usage](../../../usage.md) > [Resources](resources.md) > RolesHelper

Use `RolesHelper` when you need programmatic checks that mirror the declarative `->setAuthorize()` / `->setAuthorizeRole()` component attributes: gate a whole controller action with `hasPermission($route)`, or gate by membership with `hasRole($role)`. It reads the same tables managed by the [Roles resource](roles_resource.md), so UI hiding and backend checks stay consistent.

K-Framework provides a role system that integrates perfectly with standard Laravel Authenticable model, the roles helper can be used to hide/show components or items.

---
### Authorization on components

All the K-Framework components shares an attributes that can be set through the `->setAuthorize()`:
```php
Component::make()
    ->setAuthorize('route.to.authorize')
```

you can find more [here](../../components/shared_attributes/authorize.md).

### RolesHelper::hasPermission()

You can use the:
```php
\KFramework\Helpers\RolesHelper::hasPermission($route)
```

to check if the authenticated user has the permission to view that route. `$route` can be a Closure, a string (which is the name of the route) or an array of names of routes. Does not work on links, only on route names.
It will return true or false, it will return true only if all the routes in the array are accessible by the user.

### RolesHelper::hasRole()

You can use the:
```php
\KFramework\Helpers\RolesHelper::hasRole($role)
```

to check if the authenticated user has the role itself. `$role` can be a Closure, a string (which is the name of the role) or an array of roles names. It will return true or false, it will return true only if the user possess all the roles with those names in the array.

## Example

Controller gates the action, Blade gates the button with the same rules:

```php
// app/Http/Controllers/ReportController.php
public function export()
{
    if (!\KFramework\Helpers\RolesHelper::hasPermission('reports.export')) {
        abort(403);
    }

    if (!\KFramework\Helpers\RolesHelper::hasRole('manager')) {
        return back()->with(['error' => 'Managers only.']);
    }

    // ... export logic
}
```

```php
Button::make('Export')
    ->setURL(route('reports.export'))
    ->setAuthorize('reports.export') // hidden automatically if not permitted
    ->setAuthorizeRole('manager');
```

## See also

- [Usage](../../../usage.md)
- [Authorize shared attribute](../../components/shared_attributes/authorize.md) / [AuthorizeRole](../../components/shared_attributes/authorizeRole.md)
- [Roles resource](roles_resource.md) — where roles and route permissions are managed
- [Users resource](users_resource.md) — where roles are assigned to users
