- What is keboola/permission-checker used for?
- keboola/permission-checker is a lightweight PHP library for evaluating whether a user, role, or resource is granted a specific permission. It separates declarative permission definitions from the actual access checks, so rules are declared once and queried consistently. Each check returns a clear boolean result and can also collect denied reasons, which makes refusals easier to explain or log.
- How do I install keboola/permission-checker with Composer?
- Install it with Composer by running composer require keboola/permission-checker. Because the core is framework-agnostic, there is no mandatory service provider or config file to publish. In a Laravel application, resolve the checker through the service container or inject it into your own services.
- Does keboola/permission-checker work with Laravel, and which Laravel versions are supported?
- Yes. The core is framework-agnostic and has no Laravel coupling, so it integrates with Laravel services through dependency injection rather than a Laravel-specific API. Version support therefore depends on the library's PHP requirement rather than a specific framework release. Check the composer.json constraints on Packagist before upgrading PHP or Laravel.
- How do I get the reason a permission check was denied?
- The checker can collect denied reasons alongside the boolean result, so instead of a bare false you get an explanation of why access was refused. Use that data in error responses, logs, or audit entries. If you need a specific message shape, format the collected reasons in your own application layer.
- Can I check permissions for roles and resources, not just users?
- Yes, the library is designed for allow and deny checks against users, roles, and resources. Permission rules are declared separately from business logic, so the same rule set can answer checks for different subjects. That keeps role-based and resource-based authorization consistent across the application.
- How do I test permission rules built with keboola/permission-checker?
- Because rules are declarative and the checks are composable, you can unit test them as plain PHP without booting Laravel. Define your rules, run the checks with representative subjects, and assert both the boolean outcome and the collected denied reasons. Keeping permission definitions out of controllers makes those tests fast and focused.
- Is keboola/permission-checker a replacement for Laravel Gate and policies?
- Not exactly. Laravel Gate and policies are framework features tied to the authenticated user and Laravel's authorization pipeline, while keboola/permission-checker is a standalone PHP library focused on declarative rules and reason reporting. You can use it alongside Gate, for example inside a policy or dedicated service, when you want reusable checks that also work outside Laravel.
- What are alternatives to keboola/permission-checker?
- Common alternatives include Laravel's built-in Gate and policies and packages such as spatie/laravel-permission. Those usually persist roles and permissions in a database and are Laravel-specific, whereas keboola/permission-checker is a framework-agnostic evaluation library that focuses on checking rules rather than storing role assignments. Choose based on whether you need persistence and deep framework integration or a small, portable rule-checking core.
- Can I log authorization decisions with keboola/permission-checker?
- Yes. The denied-reason output is intended to support audit logging and to explain why access was refused. Log each decision together with the subject, the permission being checked, and the collected reasons, ideally in a structured channel. The library returns decisions only, so the actual logging implementation stays in your application.
- Is keboola/permission-checker production-ready and actively maintained?
- It is a lightweight library with no framework lock-in, which keeps its runtime surface small, and it is published by Keboola for use in Keboola-based projects. Check Packagist for the latest release and commit history before adopting it, and pin a version in composer.json. Because authorization behaviour is security-relevant, cover your rules with tests and log denials in production.