PHPackages                             gopex/laratrust-permission-creator - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. gopex/laratrust-permission-creator

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

gopex/laratrust-permission-creator
==================================

0.1.0(2y ago)08GPL3PHP

Since Jan 28Pushed 3w agoCompare

[ Source](https://github.com/gopex-team/LaratrustPermissionCreator)[ Packagist](https://packagist.org/packages/gopex/laratrust-permission-creator)[ RSS](/packages/gopex-laratrust-permission-creator/feed)WikiDiscussions main Synced today

READMEChangelog (1)DependenciesVersions (3)Used By (0)

Laratrust Permission Creator
============================

[](#laratrust-permission-creator)

[![Latest Version on Packagist](https://camo.githubusercontent.com/04c8a8eef505417842cf9725f06498cd2e0cf5d0c41612ee0d01b17caa3fb753/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f676f7065782f6c61726174727573742d7065726d697373696f6e2d63726561746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/gopex/laratrust-permission-creator)[![Total Downloads](https://camo.githubusercontent.com/e5c31128536448c4c8f6493588d4997128019f117af6c78f4b80aedecce84905/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f676f7065782f6c61726174727573742d7065726d697373696f6e2d63726561746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/gopex/laratrust-permission-creator)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

Manage your Laratrust roles and permissions using a **Code-First (Configuration-Driven)** approach. Define your ACL structure in clean PHP files, keep them version-controlled via Git, and seamlessly synchronize them with your database in both directions.

Why Use This Package?
---------------------

[](#why-use-this-package)

In large-scale applications, managing roles and permissions through database seeders or UI dashboards can become messy and hard to track across different environments (local, staging, production).

**Laratrust Permission Creator** solves this by allowing you to:

- 🛠️ **Declare Everything in Code:** Define roles, permissions, and their assignments in a simple PHP array.
- 🌿 **Git Version Control:** Track every change, addition, or deletion in your permission schema via Git.
- 🧩 **Modular Files:** Split your permissions into separate files (e.g., by module or feature) to avoid massive, unreadable configuration files.
- 🔄 **Two-Way Sync:** Push configuration changes to the database OR export an existing database schema back into code.

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

[](#installation)

You can install the package via Composer:

```
composer require gopex/laratrust-permission-creator
```

After installing the package, run the publish command to automatically generate the initial `laratrust` directory and the template configuration file in your project's root:

```
php artisan vendor:publish --tag="laratrust-permissions-file"
```

This will create the following file in your project:

- `/laratrust/RoleAndPermissions.php`

Configuration Structure
-----------------------

[](#configuration-structure)

The generated `laratrust/RoleAndPermissions.php` file returns an array with 4 main keys. Let's break down each section with clear examples:

### 1. Splitting Files (`fromFile`)

[](#1-splitting-files-fromfile)

If your application is large, don't put everything in one file. You can split your configurations into multiple separate files and link them here. The paths must be relative to your project's root directory.

```
"fromFile" => [
    "laratrust/BasicRolePermissions.php",
    "laratrust/TraderRequestPermissions.php",
],
```

### 2. Defining Permissions (`permissions`)

[](#2-defining-permissions-permissions)

You can define permissions in two ways:

- **Simple (String):** Just the permission name. `display_name` and `description` will be empy.
- **Advanced (Array):** Provide a custom `display_name` and `description`.

```
"permissions" => [
    // 1. Simple Format (No extra details needed)
    "edit_posts",

    // 2. Advanced Format (With custom display name and description)
    "delete_users" => [
        "display_name" => "Delete Registered Users", // Optional
        "description"  => "Allows a user to permanently delete accounts" // Optional
    ]
],
```

### 3. Defining Roles (`roles`)

[](#3-defining-roles-roles)

Just like permissions, roles can be defined as a simple string or a detailed array:

```
"roles" => [
    // 1. Simple Format
    "moderator",

    // 2. Advanced Format
    "super_admin" => [
        "display_name" => "Super Administrator", // Optional
        "description"  => "Has full control over the entire system" // Optional
    ]
],
```

### 4. Binding Roles to Permissions (`rolesPermissions`)

[](#4-binding-roles-to-permissions-rolespermissions)

This is where you connect your roles to their respective permissions.

```
"rolesPermissions" => [
    // Bind existing permissions to an existing role
    "super_admin" => [
        "edit_posts",
        "delete_users",
    ],

    // Smart Behavior Example:
    "support_agent" => [
        "edit_posts",
        "view_logs" // This permission will be auto-created even if missing in the 'permissions' array!
    ]
]
```

### 💡 Key Rules &amp; Smart Behaviors (How it works under the hood)

[](#-key-rules--smart-behaviors-how-it-works-under-the-hood)

To avoid breaking your application, the package follows these strict yet flexible rules during synchronization:

1. **Auto-Creation:** If you add a role or permission inside the `rolesPermissions` relation array, but forgot to declare it under the main `"roles"` or `"permissions"` tags, **the package will safely create it anyway**.
2. **Updates:** If you change the `display_name` or `description` of a role/permission in the file, running `php artisan laratrust:from-config` will instantly update those values in the database.
3. **No Redundancy Required (Independent Definition):** You do not *have* to link every single permission or role to each other.
    - If you define a permission under the `"permissions"` key but leave it out of `"rolesPermissions"`, it will still be created/updated in the database.
    - **Similarly for roles:** If you define a role under the `"roles"` key but do not assign any permissions to it inside `"rolesPermissions"`, it will still be successfully created/updated in your database for future use or manual assignment.

Usage &amp; Artisan Commands
----------------------------

[](#usage--artisan-commands)

This package provides two simple yet powerful commands to handle two-way synchronization.

### 1. Synchronize Config to Database

[](#1-synchronize-config-to-database)

When you add, modify, or remove roles and permissions inside your PHP files, run the following command to detect and apply changes directly to your database:

```
php artisan laratrust:from-config
```

*Automatically handles insertions, updates, and schema integrity.*

### 2. Export Database to Config (Reverse Sync)

[](#2-export-database-to-config-reverse-sync)

If you are introducing this package into an existing project that already has roles and permissions populated in the database, you can update or generate your configuration file based on your current database state by running:

```
php artisan laratrust:from-db
```

*Perfect for legacy projects or migrating to a code-first approach without losing existing data.*

---

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

[](#contributing)

Contributions are welcome! Please feel free to submit Pull Requests or open Issues for bugs and feature requests.

License
-------

[](#license)

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

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance62

Regular maintenance activity

Popularity5

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

 Bus Factor1

Top contributor holds 91.7% 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

Unknown

Total

1

Last Release

888d ago

### Community

Maintainers

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

---

Top Contributors

[![foroughi1380](https://avatars.githubusercontent.com/u/55579143?v=4)](https://github.com/foroughi1380 "foroughi1380 (11 commits)")[![erfanrhb](https://avatars.githubusercontent.com/u/60898556?v=4)](https://github.com/erfanrhb "erfanrhb (1 commits)")

### Embed Badge

![Health badge](/badges/gopex-laratrust-permission-creator/health.svg)

```
[![Health](https://phpackages.com/badges/gopex-laratrust-permission-creator/health.svg)](https://phpackages.com/packages/gopex-laratrust-permission-creator)
```

###  Alternatives

[vitalybaev/laravel5-dkim

Laravel 5/6 package for signing outgoing messages with DKIM.

3163.1k](/packages/vitalybaev-laravel5-dkim)

PHPackages © 2026

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