nietthijmen/laravel-roles
最新稳定版本:1.0.0
Composer 安装命令:
composer require nietthijmen/laravel-roles
包简介
This is my package laravel-roles
README 文档
README
This package provides a simple and easy way to manage roles in your laravel package.
Installation
- Install the package via composer:
composer require nietthijmen/laravel-roles
- Run the install command to publish the configuration file:
php artisan roles:install
- Grab a cup of coffee and wait for the package to be installed.
- Add the
HasRolestrait to your User model:
use Nietthijmen\LaravelRoles\Traits\HasRoles; class User extends Authenticatable { use HasRoles; // ... }
- Alias your middleware (if you want to use this)
// bootstrap/app.php withMiddleware(function (Middleware $middleware) { $middleware->alias([ 'role' => \NietThijmen\LaravelRoles\Http\Middleware\RoleMiddleware::class ]); })
- Add the RoleServiceProvider
// bootstrap/providers.php <?php return [ //... \NietThijmen\LaravelRoles\Providers\RoleServiceProvider::class ];
- You're good to go 🎉
Usage
Blade directive
@role('admin') <p>You are an admin!</p> @endrole
Middleware
You can use the middleware to protect your routes:
Route::middleware(['role:admin'])->group(function () { Route::get('/admin', function () { return 'You are an admin!'; }); });
Manual usage
auth()->user()->hasRole('admin'); // returns true if the user has the admin role
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-13