lomkit / laravel-access-control
A Laravel package that declares in one control who can see and change each Eloquent model: its perimeters drive the policies, the query scopes and the Scout searches.
Fund package maintenance!
Requires
- php: ^8.2
- ext-json: *
- laravel/framework: ^12.0|^13.0
Requires (Dev)
- guzzlehttp/guzzle: ^6.0|^7.0
- larastan/larastan: ^3.14
- laravel/pint: ^1.30
- laravel/scout: ^10|^11
- orchestra/testbench: ^10|^11
- phpstan/phpstan-deprecation-rules: ^2.0
- phpunit/phpunit: ^11.0|^12.0|^13.0
- tomasvotruba/type-coverage: ^2.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- 1.x-dev
- v0.7.0
- v0.6.0
- v0.5.0
- v0.4.1
- v0.4.0
- v0.3.2
- v0.3.1
- v0.3.0
- v0.2.0
- v0.1.6
- v0.1.5
- v0.1.4
- v0.1.3
- v0.1.2
- v0.1.1
- v0.1.0
- dev-docs/1.x-search-exceptions-and-brands
- dev-feat/1.x-search-reader-context
- dev-refactor/1.x-final-rest-extension
- dev-fix/1.x-closed-search-null-engine
- dev-docs/1.x-parent-rowless-and-inventory
- dev-fix/1.x-relations-without-connection
- dev-feat/1.x-check-readability
- dev-feat/1.x-through-parent-allowed
- dev-feat/1.x-additive-discovery
This package is auto-updated.
Last update: 2026-11-17 10:59:50 UTC
README
Laravel Access Control
Laravel Access Control allows you to fully secure your application in two key areas: Policies and Queries. Manage everything in one place!
Requirements
PHP 8.2+ and Laravel 12+
Documentation, Installation, and Usage Instructions
See the documentation for detailed installation and usage instructions.
What it does
You first need to define the perimeters concerned by your applications (php artisan make:perimeter, in app/Access/Perimeters).
Create the model control (php artisan make:control). Controls are discovered in app/Access/Controls:
class PostControl extends Control { protected string $model = Post::class; protected function perimeters(): array { return [ GlobalPerimeter::new() ->allowed(function (Model $user, Ability $ability): bool { return $user->can("{$ability} global models"); }) ->unrestricted(), ClientPerimeter::new() ->allowed(function (Model $user, Ability $ability): bool { return $user->can("{$ability} client models"); }) ->should(function (Model $user, Model $model) { return $model->client()->is($user->client); }) ->query(function (Builder $query, Model $user): void { $query->where('client_id', $user->client->getKey()); }), // ... ]; } }
Add the HasControl trait to your model, it resolves the control whose $model matches:
class Post extends Model { use HasControl; }
Then set up your policy:
class PostPolicy extends ControlledPolicy { protected string $control = PostControl::class; }
and you are ready to go !
App\Models\Post::controlled()->get() // Apply the Control to the query $user->can('view', App\Models\Post::first()) // Check if the user can view the post according to the policy
A controlled query run without an authenticated user returns no rows.
