Download the PHP package adamczykpiotr/laravel-simple-scopes-and-permissions without Composer
On this page you can find all versions of the php package adamczykpiotr/laravel-simple-scopes-and-permissions. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download adamczykpiotr/laravel-simple-scopes-and-permissions
More information about adamczykpiotr/laravel-simple-scopes-and-permissions
Files in adamczykpiotr/laravel-simple-scopes-and-permissions
Package laravel-simple-scopes-and-permissions
Short Description Simple, explicit permission checks and row-level query scopes constraining what data a user can access
License MIT
Homepage https://github.com/adamczykpiotr/laravel-simple-scopes-and-permissions
Informations about the package laravel-simple-scopes-and-permissions
Simple Scopes & Permissions for Laravel
Answer two questions in one place: what may this user do, and which rows may they see — with plain PHP enums, no magic, and a fail-closed guarantee.
Why this package
Most permission packages answer "does the user have permission X?" and stop there. In real apps the harder question is row-level: a manager may edit users, but only users in their own department. This package treats that as a first-class concept:
- Row-level scopes, enforced twice. Every scope works as an instance check (may they see this record?) and as an Eloquent query constraint (which records do we even fetch?) — so lists and detail pages can't disagree.
- Fails closed. A missing or misconfigured scope yields
WHERE 1 = 0. Mistakes hide rows; they never leak them. - Everything is an enum. Actions, permissions, and scopes are string-backed enums you define
in your app. No string tables sprinkled through the codebase, full IDE navigation, exhaustive
matchstatements. - No magic. No global scopes, no observers, no middleware guessing. Every check is an explicit call you can read at the call site.
- Explicit performer. Every check accepts the user it runs for. The "current user" fallback is a single resolver you control — which also makes impersonation trivial.
- Frontend-friendly. One call returns a
['action' => bool]map per record, so the UI can enable/disable buttons without re-implementing your rules in JavaScript.
Installation
Supports Laravel 10–13 on PHP 8.3+.
Quick start
Wire four things in config/simple-scopes-and-permissions.php, then guard your models.
1. Define your enums — actions, permissions, and scopes are app-owned string enums implementing the package contracts:
2. Tell the package who is acting — a resolver for when no explicit performer is passed:
3. Make your user model a performer:
4. Guard your models with three small hooks:
That's it. Controllers become one-liners:
Going further
The integration guide walks through a complete real-world setup:
- Authentication & impersonation — resolving the performer from the auth guard, and impersonating other users via a request header
- Designing the enums — prerequisite permissions, scope inheritance, custom scope types beyond ALL/DEPARTMENT/OWN
- Guarded models — a department-tree scope, soft delete rules, models with actions but no scoping
- Returning permissions to the frontend — per-record action maps in API resources and a class-level action map for menus and buttons
- Scoped validation rules — stopping users from referencing records they can't see
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-simple-scopes-and-permissions with dependencies
illuminate/contracts Version ^10.0||^11.0||^12.0||^13.0
spatie/laravel-package-tools Version ^1.16