44[ ![ Test] ( https://github.com/codinglabsau/laravel-roles/actions/workflows/run-tests.yml/badge.svg )] ( https://github.com/codinglabsau/laravel-roles/actions/workflows/run-tests.yml )
55[ ![ Total Downloads] ( https://img.shields.io/packagist/dt/codinglabsau/laravel-roles.svg?style=flat-square )] ( https://packagist.org/packages/codinglabsau/laravel-roles )
66
7- A super simple roles system for Laravel.
7+ A simple, flexible roles implementation for Laravel.
88
99## Installation
10- Via Composer
11-
12- ``` bash
10+ ### Install with composer
11+ ``` bash
1312$ composer require codinglabsau/laravel-roles
1413```
1514
16- ## Usage
17-
18- ### Publish Assets
19- ```
20- php artisan vendor:publish --provider="Codinglabs\Roles\RolesServiceProvider"
15+ ### Publish migrations and migrate
16+ ``` bash
17+ php artisan vendor:publish --tag=" roles-migrations"
18+ php artisan migrate
2119```
22- ##### Or Publish Specific Assets
20+
21+ ## Configuration
22+ If you need to override the default ` Role ` model, you can do that by publishing the config and setting the ` models.role ` option.
2323```
2424php artisan vendor:publish --tag="roles-config"
25- php artisan vendor:publish --tag="roles-migrations"
2625```
27- ### Migrations
28- You will need to ensure that you have published the migrations and run ` php artisan migrate ` .
26+
27+ ## Usage
2928### Add the trait
3029Add the ` HasRoles ` trait to your user model:
3130
@@ -83,6 +82,7 @@ protected $routeMiddleware = [
8382 'role' => \Codinglabs\Roles\CheckRole::class,
8483];
8584```
85+
8686And then call the middleware in your routes, seperating multiple roles with a pipe:
8787``` php
8888Route::middleware('role:employee')->...
@@ -100,7 +100,7 @@ class UserController extends Controller
100100}
101101```
102102
103- Or in the construct method in a controller:
103+ Or in the constructor of a controller:
104104``` php
105105class ManagerDashboardController extends Controller
106106{
@@ -126,6 +126,13 @@ $user->hasRole(['bar', 'baz']);
126126$user->roles;
127127```
128128
129+ ### Conditionally showing content with the blade directive
130+ ``` html
131+ @role('admin')
132+ <div >Super secret admin stuff goes here...</div >
133+ @endrole
134+ ```
135+
129136### Sharing roles with UI (Inertiajs example)
130137``` php
131138// AppServiceProvider.php
@@ -154,28 +161,7 @@ Vue.mixin({
154161<!-- SomeComponent.vue -->
155162<div v-if =" hasRole('manager')" >I am a manager</div >
156163```
157- ## Configuration
158-
159- ```
160- <?php
161-
162- return [
163- /*
164- |--------------------------------------------------------------------------
165- | Models
166- |--------------------------------------------------------------------------
167- |
168- | You may replace the models here with your own if you need to use a custom
169- | model.
170- |
171- */
172164
173- 'models' => [
174- 'role' => \Codinglabs\Roles\Role::class
175- ]
176- ];
177-
178- ```
179165## Upgrading from v1 to v2
180166Please see [ upgrading from v1 to v2] ( UPGRADING.md ) for details and instructions to avoid any issues after upgrading to v2.
181167
0 commit comments