ronu / rest-permissions
Route-based permissions for ronu/rest-generic-class: route permission catalog, channel authorization middleware, effective-permission Gate and Spatie models
Requires
- php: ^8.2
- laravel/framework: ^12.61.1 || ^13.12.0
- ronu/rest-generic-class: ^3.0
- spatie/laravel-permission: ^6.21 || ^7.0 || ^8.0
Requires (Dev)
- orchestra/testbench: ^10.9 || ^11.0
- phpunit/phpunit: ^11.5.50 || ^12.5.12
Suggests
- nwidart/laravel-modules: Required for module-aware permissions
Provides
None
Conflicts
None
Replaces
None
README
Route-based permissions for ronu/rest-generic-class: a permission catalog synchronized from your routes, the channel authorization middleware, an effective-permission Gate, role/user permission readers and the Spatie permission/role models.
Until rest-generic-class 2.x this code shipped inside the CRUD package. Since rest-generic-class 3.0 the core depends on no permission package: it authorizes through its own contracts and Laravel's Gate, and this package plugs the route permissions into them.
Requirements
| Package | Versions |
|---|---|
| PHP | 8.2+ (8.3+ on Laravel 13) |
| Laravel | 12.61.1+ or 13.12+ |
| ronu/rest-generic-class | ^3.0 |
| spatie/laravel-permission | ^6.21, ^7.0 or ^8.0 (Laravel 13: 6.25+, 7.2.4+ or 8.x) |
| nwidart/laravel-modules | optional, for module-aware permissions |
Installation
composer require ronu/rest-permissions
php artisan vendor:publish --tag=rest-permissions-config # optional: config/rest-permissions.php
The service provider is auto-discovered. It binds the request authorization scope into the core
(AuthorizationContext), so rest-generic-class.authorization.eager_relations=require_read works, and
registers the optional Gate and permission routes when enabled.
What it provides
| Piece | Class |
|---|---|
Authorization middleware (route name → permission, fail closed with on_unresolved=deny) |
Ronu\RestPermissions\Middleware\SpatieAuthorize |
Route → permission resolution (permission_ability, permission_requires, permission_global) |
Ronu\RestPermissions\Resolvers\RouteMetaResolver |
Catalog sync from routes (batch, --prune) |
HasPermissionsService::refreshPermissions() / RoutePermissionRefresher |
Role assignment, generic notation (admin.crm.clients.*) |
HasPermissionsService / TargetPermissionResolver |
Effective-permission Gate (register_gate) |
EffectivePermissionGate |
Readers and payloads (GET /permissions, compression) |
HasReadableUserPermissions, HasReadableRolePermissions, PermissionCompressor |
Spatie models with BaseModel features |
Ronu\RestPermissions\Models\SpatiePermission, SpatieRole |
| Migration script to channel authorization | vendor/ronu/rest-permissions/scripts/enable-channel-authorization.php |
Register the middleware as you did before, with its new name:
// bootstrap/app.php ->withMiddleware(function (Middleware $middleware) { $middleware->alias(['permission' => \Ronu\RestPermissions\Middleware\SpatieAuthorize::class]); })
Upgrading from rest-generic-class 2.x
composer require ronu/rest-generic-class:^3.0 ronu/rest-permissions:^1.0.- Nothing else is required to keep running: every 2.x class name (
Ronu\RestGenericClass\Core\Models\SpatiePermission,…\Middleware\SpatieAuthorize, the traits, contracts,PermissionsController, …) is aliased to its new class, lazily and with anE_USER_DEPRECATEDnotice, for the whole 1.x line. Thepermissionsblock of an existingconfig/rest-generic-class.phpis still applied whileconfig/rest-permissions.phpis not published, and theREST_AUTHZ_*/REST_PERMISSIONS_*variables keep their names. Permission route names keep their 2.x names (rest-generic-class.permissions.*). - Then, at your pace: replace
Ronu\RestGenericClass\Core\…withRonu\RestPermissions\…(the namespace moves one level up:Core\Support\Permissions→Support\Permissions,Core\Models\SpatieRole→Models\SpatieRole), publishrest-permissions-configand move thepermissionsvalues there (top level:authorization,roles_relation,routes,contracts), and movepermissions.authorization.eager_relations*torest-generic-class.authorization.*.
Documentation
- Configuration and environment variables · Configuración
- Permissions: architecture, contracts and scenarios · Permisos
- Public API (actions by ability, generic notation, catalog sync)
- Migration script to channel authorization · Script de migración
- Changelog · rest-generic-class 2.x release notes of these features
Testing
composer install
vendor/bin/phpunit # SQLite
RGC_AGGREGATE_DRIVER=mysql RGC_AGGREGATE_DATABASE=rgc_permissions_test vendor/bin/phpunit --testsuite Integration
License
MIT. See LICENSE.