Download the PHP package saeidsharafi/laravel-permission-generator without Composer

On this page you can find all versions of the php package saeidsharafi/laravel-permission-generator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-permission-generator

Laravel Permission Generator

Latest Version on Packagist Total Downloads

Generate a PHP Permission Enum class for your Laravel application based on a configuration file and keep it synchronized with your spatie/laravel-permission database tables.

Stop manually defining permission strings everywhere and prevent typos!

Features

Requirements

Installation

Install the package via Composer:

Setup

  1. Publish the configuration file:

    This creates config/permission-generator.php in your application.

  2. Customize the Configuration: Open config/permission-generator.php and define:

    • output_enum: The path where your PermissionEnum.php file will be created (e.g., app_path('Enums/PermissionEnum.php')).
    • enum_class: The fully qualified class name of your enum (e.g., App\Enums\PermissionEnum).
    • resources: List your application resources (e.g., 'user', 'post') and their associated actions. Define actions using:
      • Strings (Recommended): Use simple strings like 'view_scoped', 'create', 'update_scoped', or custom action names like 'publish', 'manage_roles'. The generator recognizes specific string values like 'view_scoped' to automatically create _any and simple/_own versions. Other strings generate literal resource.action permissions.
      • PermissionAction Enum (Optional): For standard patterns recognized by the generator, you can optionally use SaeidSharafi\LaravelPermissionGenerator\Enums\PermissionAction; and use constants like PermissionAction::VIEW_SCOPED for clarity.
      • Your Own Backed Enums (Advanced): You can use constants from your application's own BackedEnum classes (e.g., App\Enums\MyActions::APPROVE). The generator will use the Enum case's value. Important: Special logic (like _scoped generating two permissions) is only triggered by specific string values recognized by the package (like 'view_scoped'), not by the structure of your custom Enum.
    • custom_permissions: (Optional) Define standalone permissions not tied to a resource.
    • super_admin_role: (Optional) Name of the role to grant all permissions.
    • remove_stale_permissions: (Optional) Set to true to enable cleanup of old permissions during sync (use with caution).
  3. Customize Enum Templates (Optional):

    This publishes the enum template to stubs/vendor/permission-generator/enum.stub where you can customize it.

Usage Workflow

  1. Configure: Define your desired permission structure in config/permission-generator.php.

  2. Generate Enum: Create or update your PermissionEnum.php file:

    • Use --force to overwrite without confirmation.
  3. Sync Database: Ensure the permissions defined in your Enum exist in the database for spatie/laravel-permission:

    • Use --fresh with extreme caution to delete all existing permissions and their assignments before syncing.
    • Use --yes or -Y to skip confirmation prompts.
  4. Use the Enum: Import and use your generated Enum (e.g., App\Enums\PermissionEnum) in your code (Policies, Middleware, Controllers, Filament, etc.) for type safety and auto-completion.

Streamlined Workflow

The package now supports a more streamlined workflow:

  1. If you run permissions:sync without first generating the enum file, it will automatically run permissions:generate-enum for you.
  2. This makes it easier to get started with minimal setup - just configure your permissions and run php artisan permissions:sync.

Configuration Details

See the comments within the published config/permission-generator.php file for detailed explanations of each option and how to define resources and actions using strings or Enums.

Development (Linking Local Package)

If you want to contribute or modify the package locally:

  1. Clone the package repository separately.
  2. In your main Laravel project's composer.json, add a repositories section:

  3. Require the package with @dev stability in your project's composer.json:

  4. Run composer update saeidsharafi/laravel-permission-generator.

License

The MIT License (MIT). Please see the LICENSE file for more information.


All versions of laravel-permission-generator with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
illuminate/support Version ^9.0|^10.0|^11.0|^12.0
illuminate/console Version ^9.0|^10.0|^11.0|^12.0
illuminate/filesystem Version ^9.0|^10.0|^11.0|^12.0
spatie/laravel-permission Version ^5.5|^6.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package saeidsharafi/laravel-permission-generator contains the following files

Loading the files please wait ....