PHPackages                             radiatecode/laravel-permission-name-generator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. radiatecode/laravel-permission-name-generator

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

radiatecode/laravel-permission-name-generator
=============================================

Laravel package to generate permission names from route names

v0.4.3(1y ago)4870—0%MITPHPPHP ^7.1|^8.0

Since Jul 3Pushed 1y ago1 watchersCompare

[ Source](https://github.com/radiatecode/laravel-permission-name-generator)[ Packagist](https://packagist.org/packages/radiatecode/laravel-permission-name-generator)[ RSS](/packages/radiatecode-laravel-permission-name-generator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (8)Dependencies (2)Versions (15)Used By (0)

Laravel Permission Name Generator
=================================

[](#laravel-permission-name-generator)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ef48ea7f717dae05e94a9070b3153f16919d040ac83c0ae6dc831394587cfbd1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72616469617465636f64652f6c61726176656c2d7065726d697373696f6e2d6e616d652d67656e657261746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/radiatecode/laravel-permission-name-generator)[![Total Downloads](https://camo.githubusercontent.com/1248e6ae42132431ac355e055cfff8d00b9b20c062cf1c12e41a5bda58182b27/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f72616469617465636f64652f6c61726176656c2d7065726d697373696f6e2d6e616d652d67656e657261746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/radiatecode/laravel-permission-name-generator)

This package will generate permission names from route names or resources. In many application we create static permission names (ex: create-post, edit-post, delete-post) to check user's accessability, using the package can helps you to generate permission names dynamically. Permission names can be generate [panel](#panel) wise.

> **Upgrade Note:** If you are upgrade to v0.4 then you have to upgrade the older **permission-generator** [config](#configuration) file

Requirements
============

[](#requirements)

- [PHP &gt;= 7.1](https://www.php.net/)
- [Laravel 5.7|6.x|7.x|8.x|9.x|10.x](https://github.com/laravel/framework)
- [JQuery](https://jquery.com/) \[for view\]
- [Bootstrap](https://getbootstrap.com/) \[for view\]

Installation
============

[](#installation)

You can install the package via composer:

```
composer require radiatecode/laravel-permission-name-generator

```

**Publish config file**

```
php artisan vendor:publish --provider="RadiateCode\PermissionNameGenerator\PermissionNameServiceProvider" --tag="permission-generator-config"

```

**Publish permission view files (optional)**

```
php artisan vendor:publish --provider="RadiateCode\PermissionNameGenerator\PermissionNameServiceProvider" --tag="permission-views"

```

> It can be usefull when you want to customise the permissions view

Usage
=====

[](#usage)

Here are some routes

[![Stats](img/routes.png)](img/routes.png)

### Now get permissions names from that routes

[](#now-get-permissions-names-from-that-routes)

```
RadiateCode\PermissionNameGenerator\Permissions::make()->fromRoutes()->get();

```

**Output**

[![Permissions](img/permissions.png)](img/permissions.png)

PermissionGenerator trait \[Optional\]
--------------------------------------

[](#permissiongenerator-trait-optional)

From controller if you want to set prmission group title, excluded permissions or append permissions to another group then the trait becomes handy. How we use it, implement the **WithPermissionGenerator** contracts in the controller, then use the **PermissionGenerator** trait.

Available methods in **PermissionGenerator** trait

- `permissionsExclude(...$methods)` : use to exculde a route from being generated as permission name.
- `permissionsTitle(string $title)`: Use to set permissions group title
- `permissionsAppendTo(string $key)`: Permissions append to another permission group

**Example**

```
use App\Http\Controllers\Controller;
use RadiateCode\LaravelRoutePermission\Contracts\WithPermissionGenerator;
use RadiateCode\LaravelRoutePermission\Traits\PermissionGenerator;

class DepartmentController extends Controller implements WithPermissionGenerator
{
    use PermissionGenerator;

    public function __construct()
    {
         $this->permissionsTitle('Department Crud Permissions')
            ->permissionsExclude('index');// index associate route won't be generated as permission names
    }
}
```

Output:

[![PermissionTitle](img/permission-title.png)](img/permission-title.png)

**Permission Append Example:**

```
use App\Http\Controllers\Controller;
use App\Http\Controllers\Controller\DepartmentController;
use RadiateCode\LaravelRoutePermission\Contracts\WithPermissionGenerator;
use RadiateCode\LaravelRoutePermission\Traits\PermissionGenerator;

class DesignationController extends Controller implements WithPermissionGenerator
{
    use PermissionGenerator;

    public function __construct()
    {
        $this->permissionsAppendTo(DepartmentController::class);
    }
}
```

Output:

[![PermissionTitle](img/append-permissions.png)](img/append-permissions.png)

> **PermissionGenerator** trait is optional. Because if no permission group title defined, then this package dynamically generate a title based on controller name, routes can be excluded in the [config](#configuration), and permission append can be done by `custom-permission` [config](#configuration).

Permission View Builder
-----------------------

[](#permission-view-builder)

The package comes with a view builder to show generated permission names in organised way.

**Builder available methods:**

- `make(string $view, array $data = [])`: set your view.
- `withPermissions(array $permissions)`: pass generated permission names.
- `markRolePermissions(string $roleName,arra $rolePermissions,string $permissionsSaveUrl = null)`: This method helps you to mark the stored role's permissions in view so that you can identify which permissions are belongs to the role, you can define a url where you can store/update the permissions of the role
- `render()`: it render the view along with predefined data ($permissionCards, $permissionScripts), display these data in your blade. See the blade file example below

### Submiting permissions can be get by

[](#submiting-permissions-can-be-get-by)

> ```
>   $request->get('permissions');  // array of permissions
> ```

### Example of permission view

[](#example-of-permission-view)

**In controller:**

```
use RadiateCode\PermissionNameGenerator\Permissions;
use RadiateCode\PermissionNameGenerator\Facades\PermissionsView;
use App\Models\Role;

class RoleController extends Controller
{
    public function permissionsShow($id)
    {
        $role = Role::query()->findOrFail($id);

        // generate permissions from routes
        $permissions = Permissions::make()->fromRoutes()->get();

        return PermissionsView::make('app.role.permissions')
            ->withPermissions($permissions)
            ->markRolePermissions( // helps to mark the stored role's permissions in the view
                $role->role_name,
                json_decode($role->role_permissions), // assume role permissions stored as json encoded
                route('create-role-permission', $role->id) // permission save url for a role
            )->render();
    }
}
```

**In app/role/permissions.blade.php file:**

```
@extends('demo.layouts.app')

@section('content')

                    Role Permissions

                    {!! $permissionCards !!}

@endsection

@push('js')

    {!! $permissionScripts !!}
@endpush
```

**Permissions view**[![Stats](img/permission-view.png)](img/permission-view.png)

**Create the permission savings route**

```
Route::post('/role/{id}/permissions/create',[RoleController::class,'permissionStore'])->name('create-role-permission');
```

```
use \Illuminate\Http\Request;
class RoleController extends Controller
{
     public function permissionStore(Request $request,$id)
    {
        $role = Role::find($id);

        $role->role_permissions = json_encode($request->get('permissions')); // get the submitted permissions
        $role->save();

        return response()->json('success',201);
    }
}
```

Panel
-----

[](#panel)

Permissions could be generate for multiple panel, for example one application may have User panel and Admin panel, both may need different permissions. So we can achieve that by defining multiple panel, By default it is 'user' panel, assuming that all the permissions for user panel. But if you want different permissions for different panel you can generate that by defining another panel in the config.

Get the permission names for custom panel.

```
RadiateCode\PermissionNameGenerator\Permissions::make()->panel('your_custom_panel_name')->fromRoutes()->get();

```

> Note: Panel only works for routes

Configuration
-------------

[](#configuration)

Config the **config/permission-generator.php** file.

### 1. Splitter

[](#1-splitter)

If route name contains any special char then split the name by that char. It will use to generate permission text. For example if route name is **create.post** then permission text would be **Create Post**

```
'route-name-splitter-needle'    => '.',
```

### 2. Custom Permissions

[](#2-custom-permissions)

You can defined custom new permissions, add extra permissions to existing one. You can add custom-permission for custom panel.

```
'custom-permissions'  => [
    'panels' => [
        'user' => [
            // custom-permissions
        ],
        // 'admin' => [
        //    // custom-permission
        //],
    ]
],
```

> Example

```
'custom-permissions' = [
    'panels' => [
        'user' => [
            'user-permission' => ['active-user','inactive-user'],
            'bonus-permission' => [
                [
                    'name' => 'approve-own-department',
                    'text' => 'Approve Own Department'
                ],
            ]
        ],
        // 'admin' => [
        //    // custom-permission
        //],
    ]
]
```

> Note: notice the `user-permission` key which contains only permission name, if no **text** key pass the package dynamically make a **text** for the permission name. You can also add extra permissions to exisiting permission, for example `bonus-permission` is an exisitng permission, we add custom `approve-own-department` extra permission to it.

### 3. Permission Generate Controllers

[](#3-permission-generate-controllers)

This config play vital role to generate permissions because permissions will be generated only for defined controllers. Permission names will be generate, from only defined controller's route names. By Default permission names will be generated from all controller's routes for user panel. You can define custom panel and it's permission generate controllers. **Controller could be fully qualified class name or namespace-prefix.**

```
'permission-generate-controllers' => [
    'panels' => [
        'user' => [
            'App\Http\Controllers',

            // sample
            // 'App\Http\Controllers\Api',
            // App\Http\Controllers\DepartmentController::class,
            // App\Http\Controllers\DesignationController::class,
        ],
        // 'admin' => [
        //    'App\Http\Controllers\Admin',
        //],
    ]
],
```

### 4. Exclude Routes

[](#4-exclude-routes)

Exclude routes by controller. By default all auth controller's routes will be excluded from being generated as permission names for user panel. **Controller could be fully qualified class name or namespace-prefix.**

```
'exclude-controllers'           => [
    'panels' => [
        'user' => [
            'App\Http\Controllers\Auth', // exclude routes of all auth controllers
            // App\Http\Controller\Employee\EmployeeProfileController::class,
        ],
        // 'admin' => [
        //    'App\Http\Controllers\Admin\Auth',
        //],
    ]
],
```

**Or,** we can exclude routes by route name

```
'exclude-routes'  => [
    'panels' => [
        'user' => [
            // sample
            'register.user',
            'employee.profile',
            ....
            ....
        ],
        // 'admin' => [
        //   route.name,
        //],
    ]
],
```

### 6. Cache Permissions

[](#6-cache-permissions)

Caching the permission names

```
'cache-permissions' => true,
```

### 7. Permissions Section

[](#7-permissions-section)

Permissions can be grouped by section, example admin section, employee section, settings setion etc.

```
/**
 * Parmissions can be organised by section (ex: adminland, settings, employee managment etc)
 *
 * sample format: key as section name, value as generated permissions-title
 * [
 *   'adminland' => [
 *       'employee-permissions',
 *       'bonus-permissions'
 *   ],
 *   'settings' => [
 *       'office-permissions',
 *       'designation-permissions',
 *       'email-settings-permissions',
 *       'rules-permissions'
 *   ],
 *  ]
 */
'permissions-section' => [
    'panels' => [
        'user' => [
            // sample
            'adminland' => [
                'users-permissions', // all the user permissions
                'roles-permissions' // all the role permissions
            ],
            'settings' => [
                'email-settings-permissions', // all the permissions of  email settings
                DepartmentController::class, // all the permissions of department
                DesignationController::class, // all the permissions of designation
                OrganisationController::class // all the permissions of organisation
            ],
            ......,
            ......,
        ],
        // 'admin' => [
        //
        //],
    ]
]
```

Samepe Output:

[![Stats](img/permissions-section.png)](img/permissions-section.png)

Alternatively generate Permissions
----------------------------------

[](#alternatively-generate-permissions)

The package allows you to generate permission names by defining resource names.

**Example**

```
use RadiateCode\PermissionNameGenerator\Permissions;

$permissions = Permissions::make()->fromResources([
    'users',
    'posts',
])->get()

// output
[
    'users-permission' => [
        [
            'name' => 'create-users',
            'text' => 'Create Users'
        ],
        [
            'name' => 'edit-users',
            'text' => 'Edit Users'
        ],
        [
            'name' => 'show-users',
            'text' => 'Show Users'
        ],
        [
            'name' => 'delete-users',
            'text' => 'Delete Users'
        ],
        [
            'name' => 'view-users',
            'text' => 'View Users'
        ],
    ],
    'posts-permission' => [
        [
            'name' => 'create-posts',
            'text' => 'Create Posts'
        ],
        [
            'name' => 'edit-posts',
            'text' => 'Edit Posts'
        ],
        [
            'name' => 'show-posts',
            'text' => 'Show Posts'
        ],
        [
            'name' => 'delete-posts',
            'text' => 'Delete Posts'
        ],
        [
            'name' => 'view-posts',
            'text' => 'View Posts'
        ],
    ]
]
```

> Wonder how it generate, the resource permission names generate using actions, which defined in the `config` file
>
> ```
>  /**
>  * These actions used to generate permissions on given resources
>  *
>  * [Ex: If resource is posts, then permission will be ('create-posts','edit-posts','view-posts') etc]
>  */
> 'resource-actions' => [
>    'create',
>    'edit',
>    'show',
>    'delete',
>    'view',
> ]
> ```

**we can also add resource wise extra actions, which will generate extra permission names.**

```
use RadiateCode\PermissionNameGenerator\Permissions;

$permissions = Permissions::make()->fromResources([
    'users' => /*extra actions*/['delete-selected','active'],
    'posts' // no extra actions
])->get();

// output
[
    'users-permission' => [
        [
            'name' => 'create-users',
            'text' => 'Create Users'
        ],
        [
            'name' => 'edit-users',
            'text' => 'Edit Users'
        ],
        [
            'name' => 'show-users',
            'text' => 'Show Users'
        ],
        [
            'name' => 'delete-users',
            'text' => 'Delete Users'
        ],
        [
            'name' => 'view-users',
            'text' => 'View Users'
        ],
        [ // extra
            'name' => 'delete-selected-users',
            'text' => 'Delete Selected Users'
        ],
        [ // extra
            'name' => 'active-users',
            'text' => 'Active Users'
        ],
    ],
    'posts-permission' => [
        [
            'name' => 'create-posts',
            'text' => 'Create Posts'
        ],
        [
            'name' => 'edit-posts',
            'text' => 'Edit Posts'
        ],
        [
            'name' => 'show-posts',
            'text' => 'Show Posts'
        ],
        [
            'name' => 'delete-posts',
            'text' => 'Delete Posts'
        ],
        [
            'name' => 'view-posts',
            'text' => 'View Posts'
        ],
    ],
]
```

### Permission View Builder

[](#permission-view-builder-1)

**Example**

```
use RadiateCode\PermissionNameGenerator\Permissions;
use RadiateCode\PermissionNameGenerator\Facades\PermissionsView;
use App\Models\Role;

class RoleController extends Controller
{
    public function permissionsShow($id)
    {
        $role = Role::query()->findOrFail($id);

        $permissions = Permissions::make()->fromResources([
                'users',
                'posts',
                'comments'
            ])->get();

        return PermissionsView::make('app.role.permissions')
            ->withPermissions($permissions)
            ->markRolePermissions(
                $role->role_name,
                json_decode($role->role_permissions), // assume role permissions stored as json encoded
                route('create-role-permission', $role->id) // permission save url for a role
            )->render();
    }
}
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Noor Alam](https://github.com/radiatecode)
- [All Contributors](https://github.com/radiatecode/laravel-route-permission/contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~63 days

Recently: every ~145 days

Total

14

Last Release

585d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d4c058d89958aa7ac30c04fb81d7768246c72de5234a78943125b23f9bea4762?d=identicon)[radiatecode](/maintainers/radiatecode)

---

Top Contributors

[![radiatecode](https://avatars.githubusercontent.com/u/51012746?v=4)](https://github.com/radiatecode "radiatecode (31 commits)")

---

Tags

laravel-permission-nameslaravel-permissions-viewpermission-name-generatorpermission-viewlaravel-permissions-viewpermission-name-generatorlaravel-permission-names

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/radiatecode-laravel-permission-name-generator/health.svg)

```
[![Health](https://phpackages.com/badges/radiatecode-laravel-permission-name-generator/health.svg)](https://phpackages.com/packages/radiatecode-laravel-permission-name-generator)
```

###  Alternatives

[epigra/trstringhelper

PHP Türkçe Karakter Destekli String Fonksiyonları (toupper,tolower,ucfirst,ucwords,capitalizefirst) Kütüphanesi

244.1k](/packages/epigra-trstringhelper)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
