appzcoder / laravel-admin
Laravel 管理面板
v3.3.5
2022-08-09 18:37 UTC
Requires
- php: ^7.1|^8.0
- appzcoder/crud-generator: ^3.0
- illuminate/support: ^5.5|^6.0|^7.0|^8.0|^9.0
- laravelcollective/html: ^5.5|^6.0|^7.0
- spatie/laravel-activitylog: ^3.2|^4.0
README
一个用于管理用户、角色、权限及 CRUD 的管理面板。
需求
Laravel >=5.5
PHP >= 7.0
功能
- 用户、角色与权限管理器
- CRUD 生成器
- 活动日志
- 页面 CRUD
- 设置
安装
-
运行
composer require appzcoder/laravel-admin
-
安装管理包。
php artisan laravel-admin:install
服务提供者将自动被发现。
-
请确保你的用户模型有
HasRoles
特性 app/Models/User.php。class User extends Authenticatable { use Notifiable, HasRoles; ...
-
现在你可以通过生成器工具轻松地生成 CRUD。
注意:如果你使用 Laravel 7+,那么为了更好的体验,请使用 bootstrap 来构建认证。
用法
-
创建一些权限。
-
创建一些角色。
-
将权限分配给角色。
-
创建带有角色的用户。
-
为了检查认证用户的角色,请看以下内容
// Add role middleware in app/Http/Kernel.php protected $routeMiddleware = [ ... 'role' => \App\Http\Middleware\CheckRole::class, ];
// Check role anywhere if (Auth::check() && Auth::user()->hasRole('admin')) { // Do admin stuff here } else { // Do nothing } // Check role in route middleware Route::group(['namespace' => 'Admin', 'prefix' => 'admin', 'middleware' => ['auth', 'role:admin']], function () { Route::get('/', ['uses' => 'AdminController@index']); }); // Check permission in route middleware Route::group(['namespace' => 'Admin', 'prefix' => 'admin', 'middleware' => ['auth', 'can:write_user']], function () { Route::get('/', ['uses' => 'AdminController@index']); });
-
为了检查权限,请看以下内容
if ($user->can('permission-name')) { // Do something }
关于 ACL 的更多信息请见 这里
关于活动日志,请阅读 spatie/laravel-activitylog
文档
截图
作者
许可证
本项目受 MIT 许可证的许可 - 详细信息请见许可证文件