bsaleem546/roles-permissions

A Laravel package for roles and permissions management.

Maintainers

Package info

github.com/bsaleem546/RolesPermissions

pkg:composer/bsaleem546/roles-permissions

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-main 2025-07-23 08:45 UTC

This package is auto-updated.

Last update: 2026-03-23 10:46:53 UTC


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