muhammadtashfeen/lara-authpem
最新稳定版本:v1.0.1
Composer 安装命令:
composer require muhammadtashfeen/lara-authpem
包简介
A package that makes settings permissions and authorizations easier in Laravel.
README 文档
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.
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-17