Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Authorization

Authorization Laravel Package

directorytree/authorization

Native role & permission management for Laravel. Install via Composer, run migrations, add the Authorizable trait to your User model, then check roles/permissions, use caching, gate registration, and middleware. Includes customizable migrations/models and tests.

View on GitHub
Deep Wiki
Context7

Native Laravel Authorization.

Frequently asked questions about Authorization
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.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codraw/framework-extra-bundle
codraw/messenger
codraw/security
codraw/mailer
codraw/contracts
codraw/profiling
codraw/dependency-injection
codraw/tester
codraw/core
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony