- How do I install DirectoryTree/Authorization in Laravel?
- Run `composer require directorytree/authorization`, then publish migrations with `php artisan migrate`. Add the `Authorizable` trait to your `User` model and you’re ready to check roles/permissions.
- Does this package work with Laravel 10+ or only older versions?
- It’s actively maintained for Laravel 9–13. Check the [GitHub repo](https://github.com/DirectoryTree/Authorization) for the latest compatibility notes before upgrading.
- Can I customize the default migrations or use my own schema?
- Yes. Call `Authorization::ignoreMigrations()` in your `AppServiceProvider` and publish the default migrations with `php artisan vendor:publish --tag=authorization-migrations` to override them.
- How does caching work, and when should I disable it?
- Permissions are cached by default to reduce database queries. Disable caching in `.env` (`AUTHORIZATION_CACHE=false`) if you need real-time permission checks or have high-cardinality permissions.
- What’s the difference between RoleMiddleware and PermissionMiddleware?
- Use `RoleMiddleware` to restrict access by role (e.g., `admin`). Use `PermissionMiddleware` for granular checks (e.g., `edit-post`). Both throw 403 errors by default but can be customized.
- How do I test role/permission logic in PHPUnit?
- Set up permissions in tests using `PermissionRegistrar`. Example: `$this->permissionRegistrar()->createPermission('edit-post');`. Document this in your team’s testing guidelines for consistency.
- Will this package conflict with Spatie Laravel-Permission?
- Yes, avoid using both simultaneously. Choose based on features: DirectoryTree offers built-in caching and middleware, while Spatie has a larger community. Migrate data if switching.
- How do I handle permission changes in production without cache issues?
- Manually flush the cache with `php artisan cache:clear` after bulk permission updates. For dynamic systems, consider shorter cache TTLs or real-time cache invalidation logic.
- Can I use this for multi-tenancy or dynamic permission hierarchies?
- The package supports custom models and relationships, so you can extend it for multi-tenancy. However, dynamic hierarchies may require additional logic—review the `Role` and `Permission` models for hooks.
- Does DirectoryTree/Authorization support Laravel Nova or API auth (Sanctum/Passport)?
- It works with Sanctum/Passport for API authorization. For Nova, use the middleware or gates directly, but note there’s no official Nova integration—customize as needed for your panel.