Weave 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

Laravel Policies Laravel Package

arcanedev/laravel-policies

A lightweight Laravel package for working with authorization policies. It provides helpers to register, resolve, and organize policy classes, making it easier to map models to policies and keep access-control logic consistent across your application.

View on GitHub
Deep Wiki
Context7

Getting Started

  1. Install and inspect before you wire it in. composer require arcanedev/laravel-policies then open vendor/arcanedev/laravel-policies/src/. With 2 stars, one release (2020-12-01), and zero dependents, the source is the documentation — budget 15 minutes to read the manager class and service provider before writing any application code.
  2. Confirm auto-discovery. ARCANEDEV packages conventionally ship extra.laravel.providers in composer.json, so the service provider should register itself. Verify with php artisan about (Laravel 9+) or by dumping app()->getLoadedProviders(). If it is not discovered, add the provider manually to config/app.php.
  3. Publish the config (if one exists). Look for a config/policies.php in the package or a publishes() call in the provider: php artisan vendor:publish --provider="Arcanedev\LaravelPolicies\Providers\LaravelPoliciesServiceProvider". The provider's boot()/register() will tell you the exact namespace and tag.
  4. Check the framework baseline first. Laravel 8+ already auto-discovers policies by convention (App\Models\Foo → App\Policies\FooPolicy). Before adopting this package, confirm it solves a problem native discovery doesn't — typically centralised, non-conventional registration or policy grouping.
  5. First use case: register a single policy for a model that does not follow the Models/Policies naming convention. That is the smallest end-to-end test of whether the package earns its place.

Implementation Patterns

Centralised registration in a service provider. The core value of a "policies manager" is moving policy-to-model mapping out of scattered Gate::policy() calls into one place. Keep it in a dedicated AuthServiceProvider (or the package's own registration hook) so the mapping is greppable:

// app/Providers/AuthServiceProvider.php
public function boot(): void
{
    // Shape depends on the package API — verify method names in src/
    $this->app['arcanedev.policies']->register(Post::class, PostPolicy::class);
}

Group registration for domain modules. If the manager exposes a bulk/array-based registration method, use it to register a whole bounded context (e.g. all Billing models) in one call. This is the pattern that actually justifies the dependency over vanilla Gate::policy().

Keep policies framework-idiomatic. Write policies as normal Laravel policies (viewAny, create, update, delete, plus before() for super-admins). The package should be registering them, not replacing Gate — you still call $this->authorize(), Gate::allows(), and @can exactly as before.

Inspect via the Gate, not the manager. In controllers, form requests, Blade, and API resources, resolve authorization through Gate/authorize() so that swapping the manager out later is a one-file change.

Testing. Policies should be tested directly rather than through HTTP:

$policy = Gate::getPolicyFor(Post::class);
$this->assertTrue($policy->update($user, $post));

For feature tests, $this->actingAs($user)->get(...) exercises the full registration path and is the fastest way to catch a mis-registered mapping.

Integration tip: if you use a modular/multi-tenant structure, register the manager's mappings in each module's service provider rather than one monolithic AuthServiceProvider — this keeps the package's centralised registry useful without creating a merge-conflict hotspot.

Gotchas and Tips

  • Check Laravel version support explicitly. The last release is from December 2020 (Laravel 8 era). Laravel 9/10/11 tightened type declarations on Gate and Illuminate\Contracts\Auth\Access\Gate::getPolicyFor(). Run composer update and your test suite on your target framework version before committing to the package.
  • Native auto-discovery likely makes this redundant. Laravel has resolved policies by convention since 8.0. Use this package only if your naming/layout genuinely breaks the convention, or you need bulk registration. Otherwise delete the dependency and rely on the framework.
  • Bus factor is the real risk: 2 stars, 0 dependents, single maintainer, no recent release. Do not build critical authorization infrastructure on it. If you adopt it, isolate it behind your own thin service class so you can vendor or replace it in an afternoon.
  • Debugging a 403. The fastest diagnostic chain is: Gate::getPolicyFor(Post::class) (did it resolve?) → Gate::abilities() (is the ability registered?) → dump(Gate::forUser($user)->inspect('update', $post)) (Laravel 9.17+, gives the exact reason). If getPolicyFor() returns null, the manager registration never ran — check provider load order.
  • Config caching. php artisan config:cache will bake in the published config. Any dynamic/tenant-aware policy registration must happen in a provider's boot(), not in a config file, or it will break in production after caching.
  • Provider ordering. If the manager reads configuration at register() time and your own provider registers policies in boot(), make sure your provider is listed after the package provider in config/app.php (or that package discovery runs first). Mis-ordering produces silently-empty registries.
  • Extension points to probe in the source: whether the manager is bound as a singleton in the container (so you can resolve and swap it in tests), whether it supports macros, and whether it exposes a method to dump all registered mappings. A manager without an introspection method is painful to debug — add your own wrapper if needed.
  • License is MIT, so vendoring the handful of classes you actually use into app/Support/ is a legitimate, low-risk hedge against abandonment.
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.
mehedimi/laravel-amp-mail
happones/laravel-vue-i18n-generator
jwerd/inertia-table
siberfx/flysystem-wasabi
hollyit/token-replace
ippanelcom/laravel-sdk
adachsoft/changelog-linter
adachsoft/collection
payerurl/telegrambot-crypto-payment-instant-payout
dskripchenko/laravel-hybrid-search
riorizkyrainey/lara-ced
mehedimi/static-vel
zharp/zharp
nonsapiens/bigquery-model-sync
lgu-bayambang-ict-office/lgu-laravel-development-standards
andydefer/laravel-support
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel