You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+46-37Lines changed: 46 additions & 37 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
[](https://packagist.org/packages/radiatecode/laravel-permission-name-generator)
This package will generate permission names from routes. In many application we create static permission names (ex: create-post, edit-post, delete-post) to check user's accessability, using the package can helps you to generate permission names dynamically.
5
+
This package will generate permission names from route names. In many application we create static permission names (ex: create-post, edit-post, delete-post) to check user's accessability, using the package can helps you to generate permission names dynamically.
@@ -48,15 +48,17 @@ class OfficeController extends Controller implements WithPermissionGenerator
48
48
}
49
49
```
50
50
51
-
> **PermissionGenerator** trait is optional. Because if no permissible title defined, then this package dynamically generate a title based on controller name, And routes can be excluded in the config file.
51
+
> **PermissionGenerator** trait is optional. Because if no group permission title defined, then this package dynamically generate a title based on controller name. Routes can be excluded in the config file in order to tell the package not to generate those routes as permission names.
public function permissionStore(Request $request,$id)
112
-
{
113
-
$role = Role::find($id);
114
-
115
-
$role->role_permissions = json_encode($request->get('permissions')); // get the submitted permissions
116
-
$role->save();
117
-
118
-
return response()->json('success',201);
119
-
}
120
-
}
121
-
```
122
-
123
101
**In app/role/permissions.blade.php file:**
124
102
```html
125
103
@extends('layouts.app')
@@ -147,12 +125,35 @@ class RoleController extends Controller
147
125
```
148
126
149
127
> The layout is only for demo purpose, you should only notice the `$permissionCards` and `$permissionScripts` variables, and put those acording to your view layout.
public function permissionStore(Request $request,$id)
141
+
{
142
+
$role = Role::find($id);
143
+
144
+
$role->role_permissions = json_encode($request->get('permissions')); // get the submitted permissions
145
+
$role->save();
146
+
147
+
return response()->json('success',201);
148
+
}
149
+
}
150
+
```
150
151
151
152
## Configuration
152
153
153
154
Config the **config/permission-generator.php** file.
154
155
155
-
1. If route name contains any special char then split the the name by that char. It will use to generate route title. For example if route name is **create.post** then it's title would be **Create Post**
156
+
1. If route name contains any special char then split the name by that char. It will use to generate permission title. For example if route name is **create.post** then permission title would be **Create Post**
156
157
```php
157
158
/**
158
159
* Split route name by defined needle
@@ -172,18 +173,26 @@ Config the **config/permission-generator.php** file.
> Note: notice the `user-permission` key which contains only permission name, the package dynamically make a title for the permission name.
185
+
>
179
186
180
-
3. Each route associate with controllers, so you have to define the controller namespace so that the generator can generate permission names from those route associate controllers. By default all the controllers associate routes will be generated as permission names.
187
+
3. We can define controller by it's namespace, it could be whole namespace or it could be sub/prefix of controller namespace. This config play vital role to generate permissions because permissions will be generated only for our defined controllers.
181
188
182
189
```php
183
190
/**
184
191
* Define controller namespace
185
192
*
186
-
* [NT: permissions will be generated from those controller which contains the defined prefix]
193
+
* By Default permissions will be generated from all controller's routes
194
+
*
195
+
* [Note: permissions will be generated from those controller which contains the defined prefix]
187
196
*/
188
197
'controller-namespace-prefixes' => [
189
198
'App\Http\Controllers',
@@ -193,14 +202,14 @@ Config the **config/permission-generator.php** file.
193
202
194
203
```php
195
204
/**
196
-
* Exclude routes by controller or controller namespace-prefix
205
+
* Exclude routes by controller whole namespace or sub/prefix of controller namespace
197
206
*
198
-
* [NT: We can exclude routes by defining controller name or namespace-prefix. All the routes associated with controller will be excluded]
207
+
* By default all auth controller's routes will be excluded from being generated as permission names
208
+
*
209
+
* [Note: We can exclude routes by defining controller name or namespace-prefix. All the routes associated with controller will be excluded]
199
210
*/
200
211
'exclude-controllers' => [
201
-
/*
202
-
* exclude every route which associate with the prefix namespace
203
-
*/
212
+
// exclude every route which associate with the namespace-prefix of controller
0 commit comments