{"id":20523091,"url":"https://github.com/itstructure/laravel-rbac","last_synced_at":"2025-04-05T21:06:10.339Z","repository":{"id":51360835,"uuid":"141863545","full_name":"itstructure/laravel-rbac","owner":"itstructure","description":"Laravel package for RBAC manage","archived":false,"fork":false,"pushed_at":"2025-02-28T11:12:43.000Z","size":298,"stargazers_count":53,"open_issues_count":3,"forks_count":10,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-29T20:03:02.024Z","etag":null,"topics":["laravel","laravel-rbac","permission","rbac","role"],"latest_commit_sha":null,"homepage":"https://pack-develop.info/en/product/rbac-laravel-package","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/itstructure.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-07-22T03:40:51.000Z","updated_at":"2025-03-22T21:11:53.000Z","dependencies_parsed_at":"2025-02-26T07:19:33.973Z","dependency_job_id":"2bd6f9aa-243a-4750-b674-61e6528513db","html_url":"https://github.com/itstructure/laravel-rbac","commit_stats":{"total_commits":17,"total_committers":1,"mean_commits":17.0,"dds":0.0,"last_synced_commit":"de30bfcb11b0cadadaefada3da27445cb725a437"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itstructure%2Flaravel-rbac","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itstructure%2Flaravel-rbac/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itstructure%2Flaravel-rbac/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itstructure%2Flaravel-rbac/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/itstructure","download_url":"https://codeload.github.com/itstructure/laravel-rbac/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247399871,"owners_count":20932876,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["laravel","laravel-rbac","permission","rbac","role"],"created_at":"2024-11-15T22:37:55.625Z","updated_at":"2025-04-05T21:06:10.318Z","avatar_url":"https://github.com/itstructure.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel RBAC package\n\n[![Latest Stable Version](https://poser.pugx.org/itstructure/laravel-rbac/v/stable)](https://packagist.org/packages/itstructure/laravel-rbac)\n[![Latest Unstable Version](https://poser.pugx.org/itstructure/laravel-rbac/v/unstable)](https://packagist.org/packages/itstructure/laravel-rbac)\n[![License](https://poser.pugx.org/itstructure/laravel-rbac/license)](https://packagist.org/packages/itstructure/laravel-rbac)\n[![Total Downloads](https://poser.pugx.org/itstructure/laravel-rbac/downloads)](https://packagist.org/packages/itstructure/laravel-rbac)\n[![Build Status](https://scrutinizer-ci.com/g/itstructure/laravel-rbac/badges/build.png?b=master)](https://scrutinizer-ci.com/g/itstructure/laravel-rbac/build-status/master)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/itstructure/laravel-rbac/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/itstructure/laravel-rbac/?branch=master)\n\n## 1 Introduction\n\n**LaRbac** - Package for the Laravel framework which provides management with the next data:\n- Roles\n- Permissions\n- Assign roles for users\n\n![RBAC package structure](https://github.com/itstructure/laravel-rbac/blob/master/laravel_rbac_structure_en.jpg)\n\n## 2 Dependencies\n\n- laravel 8+ | 9+ | 10+ | 11+ | 12+\n- Bootstrap 4 for styling\n- JQuery\n- php \u003e= 7.3.0\n- composer\n\n## 3 Installation\n\n**Note!**\n\nVersion **3.x** is for laravel **8+**, **9+**, **10+**, **11+**, **12+**.\n\nVersion **2.x** is for laravel **6** or **7**. You can use branch `laravel67-rbac` with **2.x** versions.\n\n### 3.1 General installation from remote repository\n\nRun the composer command:\n\n`composer require itstructure/laravel-rbac \"^3.0.18\"`\n\n### 3.2 Next internal installation steps\n\n**Notes:**\n\n- Make sure that a table for the users is already existing in your project.\n\n- Make sure that a model for the users table is already existing in your project.\n\n**Recommendation:**\n\nIf you don't have any layout yet, it is useful to install for example [AdminLTE](https://github.com/jeroennoten/Laravel-AdminLTE) \nor you can make your special any layout template. \nCause in this package there is no a layout specially. But in config it is necessary to set it (see the next point 2 about a configure).\n\nLet's go:\n\n1. Publish files.\n\n    **Note:** `rbac.php` config file and seeders `LaRbacDatabaseSeeder`, `PermissionSeeder`, `RoleSeeder` must be published surely!\n\n    - To publish config run command:\n    \n        `php artisan rbac:publish --only=config`\n        \n        It stores config file to `config` folder.\n        \n    - To publish seeders run command:\n        \n        `php artisan rbac:publish --only=seeders`\n        \n        It stores seeder files to `database/seeders` folder.\n        \n    - To publish migrations run command:\n            \n        `php artisan rbac:publish --only=migrations`\n        \n        It stores migration files to `database/migrations` folder.\n            \n    - To publish views run command:\n                \n        `php artisan rbac:publish --only=views`\n        \n        It stores view files to `resources/views/vendor/rbac` folder.\n        \n    - To publish translations run command:\n                    \n        `php artisan rbac:publish --only=lang`\n        \n        It stores translation files to `resources/lang/vendor/rbac` folder.\n        \n    - To publish all parts run command without `only` argument:\n    \n        `php artisan rbac:publish`\n        \n    Else you can use `--force` argument to rewrite already published files.\n    \n2. Configure published `config/rbac.php` file:\n\n    - set `layout`. Example: `'layout' =\u003e 'adminlte::page'`\n    \n    - change `userModelClass` if it is needed to change\n    \n    - set `adminUserId` which you wanted to be with the role of administrator. **At least at the beginning stage**.\n    \n        It is necessary for the next time system to let you go into the Rbac control panel, after you assigned an administrator role for you (Later see point **4**).\n        \n    - Most likely you have to change `memberNameAttributeKey`.\n    \n        It is to display the user name in control panel by `getMemberNameAttribute()` method of `Administrable` trait. It can be **string** or a **callback**:\n    \n        ```php\n        'memberNameAttributeKey' =\u003e function ($row) {\n            return $row-\u003efirst_name . ' ' . $row-\u003elast_name;\n        }\n        ```\n    \n3. Tuning your `User` model (as shown in **4.1** point):\n\n    - Implement `User` model from `RbacUserInterface`.\n   \n    - Add **roles** attribute to `$fillable`.\n   \n    - Apply `Administrable` trait.\n\n4. Run command to run migrations and seeders:\n\n    `php artisan rbac:database`\n    \n    Or optional:\n    \n    To run just migrations `php artisan rbac:database --only=migrate`\n    \n    To run just seeds `php artisan rbac:database --only=seed`\n    \n    - Alternative variant for seeders.\n    \n        You can set published rbac `LaRbacDatabaseSeeder` seeder class in to a special `DatabaseSeeder`:\n            \n        ```php\n        use Illuminate\\Database\\Seeder;\n        ```\n        \n        ```php\n        class DatabaseSeeder extends Seeder\n        {\n            public function run()\n            {\n                $this-\u003ecall(LaRbacDatabaseSeeder::class);\n            }\n        }\n        ```\n        \n        and run command: `php artisan db:seed`.\n    \n5. Run command to set Admin role for user with identifier `adminUserId`, defined in **2** point:\n\n    `php artisan rbac:admin`\n\n## 4 Usage\n\n**Notes**:\n\n- Make sure you use a **Bootstrap 4** for styling and **JQuery** in your application.\n\n- Make sure that a laravel initial factory authorization is already working in your application.\n\n### 4.1 Model part\n\nAccording with the `Itstructure\\LaRbac\\Interfaces\\RbacUserInterface` use functions from `Itstructure\\LaRbac\\Traits\\Administrable` trait as in example:\n\n```php\nnamespace App;\n\nuse Illuminate\\Notifications\\Notifiable;\nuse Illuminate\\Foundation\\Auth\\User as Authenticatable;\nuse Itstructure\\LaRbac\\Interfaces\\RbacUserInterface;\nuse Itstructure\\LaRbac\\Traits\\Administrable;\n```\n\n```php\nclass User extends Authenticatable implements RbacUserInterface\n{\n    use Notifiable, Administrable;\n\n    protected $fillable = [\n        'name', 'email', 'password', 'roles'\n    ];\n\n    protected $hidden = [\n        'password', 'remember_token',\n    ];\n}\n```\n\n### 4.2 Routes part\n\nThere are already integrated base RBAC routes to manage **users**, **roles** and **permissions**. See in `routes.php` package file.\n\nThey are guarded by the next:\n\n- middleware `auth` (editable by config).\n- permission `can:administrate` (editable by config).\n\nThis routes allow you to go to the next routes:\n\n- **Users section**\n\n    For get request method\n\n    - `http://example-domain.com/rbac/users`\n    - `http://example-domain.com/rbac/users/show/{id}`\n    - `http://example-domain.com/rbac/users/edit/{id}`\n\n    For post request method\n\n    - `http://example-domain.com/rbac/users/update/{id}`\n    - `http://example-domain.com/rbac/users/delete`\n    \n- **Roles section**\n\n    For get request method\n\n    - `http://example-domain.com/rbac/roles`\n    - `http://example-domain.com/rbac/roles/show/{id}`\n    - `http://example-domain.com/rbac/roles/create`\n    - `http://example-domain.com/rbac/roles/edit/{role}`\n\n    For post request method\n\n    - `http://example-domain.com/rbac/roles/store`\n    - `http://example-domain.com/rbac/roles/update/{role}`\n    - `http://example-domain.com/rbac/roles/delete`\n    \n- **Permissions section**\n\n    For get request method\n\n    - `http://example-domain.com/rbac/permissions`\n    - `http://example-domain.com/rbac/permissions/show/{id}`\n    - `http://example-domain.com/rbac/permissions/create`\n    - `http://example-domain.com/rbac/permissions/edit/{permission}`\n\n    For post request method\n\n    - `http://example-domain.com/rbac/permissions/store`\n    - `http://example-domain.com/rbac/permissions/update/{permission}`\n    - `http://example-domain.com/rbac/permissions/delete`\n\n### 4.3 Gates part\n\nThere are already integrated base RBAC gates to access control in your application to some of the resources. See provider file `RbacAuthServiceProvider.php`.\n\nIt provides the next gate definitions:\n\n- `administrate`\n- `assign-role`\n- `delete-member`\n- `view-record`\n- `create-record`\n- `update-record`\n- `delete-record`\n- `publish-record`\n\nRead more in [Laravel gates](https://laravel.com/docs/9.x/authorization#gates)\n\n## 5 View examples\n\n**Users**\n\n![RBAC package structure](https://github.com/itstructure/laravel-rbac/blob/master/laravel_rbac_users_en.JPG)\n\n**Roles**\n\n![RBAC package structure](https://github.com/itstructure/laravel-rbac/blob/master/laravel_rbac_roles_en.JPG)\n\n**Permissions**\n\n![RBAC package structure](https://github.com/itstructure/laravel-rbac/blob/master/laravel_rbac_permissions_en.JPG)\n\n## License\n\nCopyright © 2018-2025 Andrey Girnik girnikandrey@gmail.com.\n\nLicensed under the [MIT license](http://opensource.org/licenses/MIT). See LICENSE.txt for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitstructure%2Flaravel-rbac","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitstructure%2Flaravel-rbac","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitstructure%2Flaravel-rbac/lists"}