Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Added ability to add individual Permissions to User #876

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,16 @@ $admin->name = 'admin';
$admin->display_name = 'User Administrator'; // optional
$admin->description = 'User is allowed to manage and edit other users'; // optional
$admin->save();


$edit_post = new Permission();
$edit_post->name = 'edit_own_post';
$edit_post->display_name = 'Can Edit Self Created Post'; // optional
$edit_post->description = 'User is allowed to edit only his own posts'; // optional
$edit_post->save();
```

Next, with both roles created let's assign them to the users.
Next, with both roles and the new permission created let's assign them to the users.
Thanks to the `HasRole` trait this is as easy as:

```php
Expand All @@ -229,6 +236,12 @@ $user->attachRole($admin); // parameter can be an Role object, array, or id

// or eloquent's original technique
$user->roles()->attach($admin->id); // id only

// permission attach alias
$user->attachPermission($edit_post); // parameter can be an Permission object, array, or id

// or eloquent's original technique
$user->permission()->attach($edit_post->id); // id only
```

Now we just need to add permissions to those Roles:
Expand Down
Loading