bsaleem546/roles-permissions 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

bsaleem546/roles-permissions

Composer 安装命令:

composer require bsaleem546/roles-permissions

包简介

A Laravel package for roles and permissions management.

README 文档

README

A Laravel package for advanced roles and permissions management.

Features

  • Role and permission models with many-to-many relationships
  • Middleware for dynamic permission gates
  • Database migrations and seeders for roles and permissions
  • Easy publishing of models, migrations, seeders, and middleware into your Laravel app for customization

Installation & Setup

1. Require the Package

If your package is not on Packagist, add it as a local path repository in your Laravel app's composer.json:

"repositories": [
    {
        "type": "path",
        "url": "/absolute/path/to/RolesPermissions"
    }
]

Then require it:

composer require bsaleem546/roles-permissions:dev-main

2. Publish Package Files

After installation, publish the package's files into your Laravel app:

php artisan vendor:publish --tag=roles-permissions-models
php artisan vendor:publish --tag=roles-permissions-migrations
php artisan vendor:publish --tag=roles-permissions-seeders
php artisan vendor:publish --tag=roles-permissions-middleware

This will copy:

  • Models to app/Models/
  • Migrations to database/migrations/
  • Seeders to database/seeders/
  • Middleware to app/Http/Middleware/

3. Run Migrations

php artisan migrate

4. Seed the Database

php artisan db:seed --class=RoleSeeder
php artisan db:seed --class=PermissionSeeder

5. Register the Service Provider (if not auto-discovered)

Add to config/app.php in the providers array:

RolesPermissions\RolesPermissionsServiceProvider::class,

Usage

Models

Use the published models in app/Models/Role.php and app/Models/Permission.php as you would any Eloquent model. They include all necessary relationships and constants.

Middleware

The AuthGateMiddleware is published to app/Http/Middleware/AuthGateMiddleware.php and registered as auth.gate by the service provider. Use it in your routes:

Route::middleware(['auth.gate'])->group(function () {
    // Protected routes
});

Permission Checks

Use Laravel's Gate system to check permissions:

use Illuminate\Support\Facades\Gate;

if (Gate::allows('dashboard')) {
    // User can access the dashboard
}

Or in Blade:

@can('dashboard')
    ...
@endcan

Traits

The package provides a trait for permission checks:

use RolesPermissions\Traits\HasPermissionCheck;

class SomeController extends Controller
{
    use HasPermissionCheck;

    public function someAction()
    {
        $this->checkPermissionOrAbort('dashboard');
        // ...
    }
}

Customization

  • Edit the published models, seeders, middleware, and migrations as needed for your application.
  • Add or modify permissions and roles by updating the seeders or using Eloquent directly.

Updating the Package

If you update the package and want to overwrite the published files, re-run the vendor:publish commands with the --force flag:

php artisan vendor:publish --tag=roles-permissions-models 
php artisan vendor:publish --tag=roles-permissions-migrations
php artisan vendor:publish --tag=roles-permissions-seeders 
php artisan vendor:publish --tag=roles-permissions-middleware

License

MIT

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-23