med-ezzairi/account-module
Composer 安装命令:
composer require med-ezzairi/account-module
包简介
A module letting you make Account management easy, including users, groups, permissions & roles
README 文档
README
This module lets you manage Groups of users, setup groups permissions and per user permissions, the reason behind this module is that you are free to define permissions in your config file as text and assign them to groups or users as you need. The final result is that you could check the user permission based on text (permission) you defined not ids (auto increment) used by other packages/modules.
Installation
This module requires using the package nwidart/laravel-modules see the page nwidart/laravel-modules.
composer require med-ezzairi/account-module
Config and Migration
Check the config file under Modules/Account/Config/account.php to setup tables names.
Update the Model/Entity User in general under app/Models/User
php artisan module:migrate account
Update the Model User to use the trait Modules\Account\Traits\UserUsingGroupsAndPermissions;
as follow:
<?php
namespace App\Models;
...
use Modules\Account\Traits\UserUsingGroupsAndPermissions;
class User extends Authenticatable
{
use HasFactory, Notifiable, UserUsingGroupsAndPermissions;
public $table = 'users';
Usage
- Permission definition
Check the file Modules/Account/Config/permissions.php to see the permissions definition.
The definition follows the:
<?php
return [
'module.entity' => [
'action1' => "A description of the permission",
'action2' => "Second description of the permission",
//Examples
'index' => "List users",
'create' => "Create new users",
'activate' => "Activate users account",
'disable' => "Disable users account",
],
'shop.orders' => [
'create' => "Create an order",
'edit' => trans("shop.order_permission_edit"), // to use the translation
'view' => "View an order",
'delete' => "Delete an order",
],
];
- Permission assignment
Check the url: http://yourapplication/account (like: http://localhost/account)
- Permission verification
After Permission definition and assignment we could check the User's permission by calling the helper allowed(permission_name), like this allowed('shop.orders.delete'); from any where in your code (controller, service or repository). If the connected user is allowed the code will continue execution, if not allowed an exception will be thrown (check the Modules\Account\Exceptions\AuthorizationException)
- Per Resource Permission
We have a logic to handle per-resource-permissions for specific Resources/Models/Entities. To use the ResourcePermission, add the trait Modules\Account\Traits\HasResourcePermission to the resource/model/entity and specify the protected $resourcePermission attribute.
use Modules\Account\Traits\HasResourcePermission;
use App\Permissions\Shop\OrderResourcePermission;
class Order extends Model
{
use HasResourcePermission; // add the trait that define the logic
protected $table = 'shop_orders';
protected $primaryKey = 'id';
protected $guarded = ['id'];
# define and set the attribute: give the class that define how to handle each action
protected $resourcePermission = OrderResourcePermission::class;
In the OrderResourcePermission we need to create a method that will handle the permission logic, the method name must be same permission action, example shop.orders.delete (the action here is: delete)
<?php
namespace App\Permissions\Shop;
use Modules\Account\Permissions\ResourcePermission;
use App\Models\Shop\Order;
use App\User;
class OrderResourcePermission extends ResourcePermission {
/**
* Check the user permission on the resource
*
* @param User $user
* @param Order $resource
* @return boolean
*/
protected function delete( User $user, Order $resource )
{
$role_id = $user->getRole();
return $user->id == $resource->id || $role_id == 'admin';
}
}
To check if the connect user is able/permitted to perform the requested action/permission on a resource, use the same helper, like this allowed('shop.orders.delete', $order);. Here we passed the resource as the second parameter.
Note: Be careful with per-resource-permission, the user should already has the permission to perform the action (direct permission assignment or assigned via group) and after checking the permission we will check if he is permitted for that action on that resource.
Tests
Sorry, no tests are provided for now.
Specific Help or Custom Integration
Please let me know about your need and I will help you.
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
License
med-ezzairi/account-module 适用场景与选型建议
med-ezzairi/account-module 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 10 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「group」 「laravel」 「permission」 「account」 「role」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 med-ezzairi/account-module 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 med-ezzairi/account-module 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 med-ezzairi/account-module 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Provides a PHP interface for The AAM Group's RESTful API.
Provides a PHP interface for The AAM Group's payment processor.
This package provides a flexible way to add Role-based Permissions to Laravel 6.x
This package provides a flexible way to add Role-based Permissions to Laravel
Flexible Content & Repeater Fields for Laravel Nova.
Simple Roles and Permissions for Laravel 5.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-30