muhammadtashfeen / lara-authpem
A package that makes settings permissions and authorizations easier in Laravel.
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/muhammadtashfeen/lara-authpem
Requires
- php: ^8.3
Requires (Dev)
- laravel/pint: dev-main
- orchestra/testbench: ^9.5
- phpunit/phpunit: ^11.0
This package is auto-updated.
Last update: 2025-12-17 21:17:20 UTC
README
LaraAuthpem is a Laravel package for flexible role & permission management, bringing attribute-based access
control to your Laravel applications.
With LaraAuthpem, you can easily protect routes, controllers, and actions by simply attaching PHP attributes. ๐ก๏ธ
โจ Features
- ๐ Assign multiple roles & permissions to users
- โก Middleware for automatic role & permission checks
- ๐งฉ Attribute-based access control with PHP 8+ attributes
- ๐ Protect routes and controllers with minimal boilerplate
- ๐ ๏ธ Simple integration with Laravel authentication
- ๐ฆ Service classes to handle role & permission logic
๐ฆ Installation
Install via Composer:
composer require muhammadtashfeen/lara-authpem
(Optional) Publish the service provider:
php artisan vendor:publish --provider="MuhammadTashfeen\LaraAuthpem\Providers\AuthServiceProvider"
๐ User Model Requirements
Your User model must implement the following methods:
public function getRoles(): array { return ['admin', 'editor']; // example } public function getPermissions(): array { return ['view_users', 'create_users']; // example }
โก How these arrays are populated is entirely up to you โ they can come from the database, config, or any custom logic.
The important part is that they always return arrays of role names and permission names.
๐ Usage
๐ก๏ธ Middleware Protection
Use the middleware alias mt.authpem to protect routes:
Route::middleware(['mt.authpem'])->group(function () { Route::get('/users', [UserController::class, 'index']); });
๐งฉ Attribute Usage (Controller-Level)
use MuhammadTashfeen\LaraAuthpem\Attributes\HasRole; use MuhammadTashfeen\LaraAuthpem\Attributes\HasPermission; #[HasRole('admin')] #[HasPermission('view_users')] public function index() { // Only accessible by admins with view_users permission }
๐งช Testing
Run PHPUnit tests:
vendor/bin/phpunit
โ๏ธ Compatibility
- PHP: ^8.3
- Laravel: 10.x
- PHPUnit: ^11.0 (for testing)
- Orchestra Testbench: ^9.5 (for testing)
- Laravel Pint: dev-main (optional, for code style)
๐ค Contributing
Contributions are welcome!
Feel free to open issues or submit PRs to improve LaraAuthpem.
๐ License
LaraAuthpem is open-sourced software licensed under the MIT license.