PHPackages                             jefremassingue/spatie-permission-generate - 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. jefremassingue/spatie-permission-generate

ActiveLibrary

jefremassingue/spatie-permission-generate
=========================================

Package for genarate permissions

v1.0.0(2y ago)0256↓100%[1 PRs](https://github.com/jefremassingue/spatie-permission-generate/pulls)MITPHPPHP &gt;=7.3

Since Apr 1Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/jefremassingue/spatie-permission-generate)[ Packagist](https://packagist.org/packages/jefremassingue/spatie-permission-generate)[ Docs](https://github.com/jefremassingue/spatie-permission-generate)[ RSS](/packages/jefremassingue-spatie-permission-generate/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (3)Versions (3)Used By (0)

Spatie Permission Generate
==========================

[](#spatie-permission-generate)

Spatie Permission Generate is a package that generates permissions for spatie/laravel-permission based on the directory, controller class name, and methods.

For instance, Admin\\UserController with index method =&gt; will have the permission `admin-user-index`.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require jefremassingue/spatie-permission-generate:"dev-main"
```

Usage
-----

[](#usage)

Before using the package, you need to install and configure spatie/laravel-permission ().

```
// Run synchronizelPermission method to generate permissions
    $hasGenarate = \Jefre\SpatiePermissionGenerate\SpatiePermissionGenerate::synchronizelPermission();
```

```
// Change the guard name for permissions with a given prefix
    $numPermissionsUpdated = \Jefre\SpatiePermissionGenerate\SpatiePermissionGenerate::changeGuardWithPrefix('api-', 'api');

```

### Instalation in Laravel

[](#instalation-in-laravel)

```
// Set the following keys in your `.env` file:

SPG_CONTROLLERS_ROOT_PATH='app/Http/Controllers'
SPG_IGNORE_CLASSES_FILES='Controller,Helper\Upload, Other classes you want ignore'
SPG_CONTROLLER_CLASSES_SUFFIX='Controller,_controller'
SPG_IGNORE_METHODS_AND_FUNCTIONS='__construct'
SPG_DEFAULT_GUARD='web'
```

KeyDescriptionExample`SPG_CONTROLLERS_ROOT_PATH`The root path where the controllers are located. You have to use `/``app/Http/Controllers``SPG_IGNORE_CLASSES_FILES`The classes that should be ignored (separated by comma). You have to use `\\``'Controller,Admin\PermissionGeneratorController,Helper\Upload'``SPG_CONTROLLER_CLASSES_SUFFIX`The suffixes for the controller classes.`'_controller,Controller'``SPG_IGNORE_METHODS_AND_FUNCTIONS`The methods and functions that should be ignored (separated by comma).`'__construct,pay'``SPG_DEFAULT_GUARD`The default guard.`'web'`### Testing

[](#testing)

To run the tests, execute the following command:

```
composer test
```

### Example

[](#example)

Consider a file located in `/app/Http/Controllers/API/UserController.php`:

```
