-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Naming all roles to {model}-{action} (#13)
Like we discussed in #5 Here is the first part of the renaming all the roles to the same structure.
- Loading branch information
Showing
2 changed files
with
17 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,7 +117,7 @@ if (auth()->user()->can('permission_name')) { | |
You can also use the helper method: | ||
|
||
```php | ||
if (hasPermissions('create-post')) { | ||
if (hasPermissions('post-create')) { | ||
dd('You are allowed to access'); | ||
} else { | ||
dd('You are not allowed to access'); | ||
|
@@ -127,7 +127,7 @@ if (hasPermissions('create-post')) { | |
OR | ||
|
||
```php | ||
if (hasPermissions('create-post', 'post-edit')) { | ||
if (hasPermissions('post-create', 'post-edit')) { | ||
dd('You are allowed to access'); | ||
} else { | ||
dd('You are not allowed to access'); | ||
|
@@ -161,11 +161,11 @@ getRoles(); | |
To protect routes based on roles and permissions, you can use the provided middleware. For example, to allow only users with the `user` role and `create-user` permission: | ||
|
||
```php | ||
Route::group(['middleware' => ['role:user,create-user']], function () { | ||
Route::group(['middleware' => ['role:user,user-create']], function () { | ||
// Protected routes go here | ||
}); | ||
|
||
Route::group(['middleware' => ['role:admin,create-post']], function () { | ||
Route::group(['middleware' => ['role:admin,post-create']], function () { | ||
// Protected routes go here | ||
}); | ||
``` | ||
|
@@ -189,7 +189,7 @@ You can also use Blade directives to display content based on the user's role: | |
You can also use Blade directives to display content based on the user's permissions: | ||
|
||
```php | ||
@permission('create-post') | ||
@permission('post-create') | ||
{{ __('You can create a post') }} | ||
@endpermission | ||
``` | ||
|
@@ -227,8 +227,8 @@ class RolePermissionSeeder extends Seeder | |
private function seedPermissions(): void | ||
{ | ||
$permissions = [ | ||
'create-post', | ||
'create-user', | ||
'post-create', | ||
'user-create', | ||
]; | ||
|
||
foreach ($permissions as $permissionName) { | ||
|
@@ -239,8 +239,8 @@ class RolePermissionSeeder extends Seeder | |
private function seedRoles(): void | ||
{ | ||
$roles = [ | ||
'admin' => ['create-post', 'post-edit', 'post-delete', 'post-update'], | ||
'user' => ['create-user', 'user-edit', 'user-delete', 'user-update'], | ||
'admin' => ['post-create', 'post-edit', 'post-delete', 'post-update'], | ||
'user' => ['user-create', 'user-edit', 'user-delete', 'user-update'], | ||
]; | ||
|
||
foreach ($roles as $roleName => $permissionNames) { | ||
|
@@ -262,14 +262,14 @@ class RolePermissionSeeder extends Seeder | |
'email' => '[email protected]', | ||
'password' => Hash::make('admin'), | ||
'roles' => ['admin'], | ||
'permissions' => ['create-post'], | ||
'permissions' => ['post-create'], | ||
], | ||
[ | ||
'name' => 'User', | ||
'email' => '[email protected]', | ||
'password' => Hash::make('user'), | ||
'roles' => ['user'], | ||
'permissions' => ['create-user'], | ||
'permissions' => ['user-create'], | ||
], | ||
]; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,8 +30,8 @@ class RolePermissionSeeder extends Seeder | |
private function seedPermissions(): void | ||
{ | ||
$permissions = [ | ||
'create-post', | ||
'create-user', | ||
'post-create', | ||
'user-create', | ||
]; | ||
|
||
foreach ($permissions as $permissionName) { | ||
|
@@ -45,8 +45,8 @@ class RolePermissionSeeder extends Seeder | |
private function seedRoles(): void | ||
{ | ||
$roles = [ | ||
'admin' => ['create-post', 'post-edit', 'post-delete', 'post-update'], | ||
'user' => ['create-user', 'user-edit', 'user-delete', 'user-update'], | ||
'admin' => ['post-create', 'post-edit', 'post-delete', 'post-update'], | ||
'user' => ['user-create', 'user-edit', 'user-delete', 'user-update'], | ||
]; | ||
|
||
foreach ($roles as $roleName => $permissionNames) { | ||
|
@@ -71,14 +71,14 @@ class RolePermissionSeeder extends Seeder | |
'email' => '[email protected]', | ||
'password' => Hash::make('admin'), | ||
'roles' => ['admin'], | ||
'permissions' => ['create-post'], | ||
'permissions' => ['post-create'], | ||
], | ||
[ | ||
'name' => 'User', | ||
'email' => '[email protected]', | ||
'password' => Hash::make('user'), | ||
'roles' => ['user'], | ||
'permissions' => ['create-user'], | ||
'permissions' => ['user-create'], | ||
], | ||
]; | ||
|
||
|