| @@ 19-36 (lines=18) @@ | ||
| 16 | * |
|
| 17 | * @return $this |
|
| 18 | */ |
|
| 19 | public function givePermissionTo(...$permissions) |
|
| 20 | { |
|
| 21 | $permissions = collect($permissions) |
|
| 22 | ->flatten() |
|
| 23 | ->map(function ($permission) { |
|
| 24 | return $this->getStoredPermission($permission); |
|
| 25 | }) |
|
| 26 | ->each(function ($permission) { |
|
| 27 | $this->ensureModelSharesGuard($permission); |
|
| 28 | }) |
|
| 29 | ->all(); |
|
| 30 | ||
| 31 | $this->permissions()->saveMany($permissions); |
|
| 32 | ||
| 33 | $this->forgetCachedPermissions(); |
|
| 34 | ||
| 35 | return $this; |
|
| 36 | } |
|
| 37 | ||
| 38 | /** |
|
| 39 | * Remove all current permissions and set the given ones. |
|
| @@ 85-102 (lines=18) @@ | ||
| 82 | * |
|
| 83 | * @return $this |
|
| 84 | */ |
|
| 85 | public function assignRole(...$roles) |
|
| 86 | { |
|
| 87 | $roles = collect($roles) |
|
| 88 | ->flatten() |
|
| 89 | ->map(function ($role) { |
|
| 90 | return $this->getStoredRole($role); |
|
| 91 | }) |
|
| 92 | ->each(function ($role) { |
|
| 93 | $this->ensureModelSharesGuard($role); |
|
| 94 | }) |
|
| 95 | ->all(); |
|
| 96 | ||
| 97 | $this->roles()->saveMany($roles); |
|
| 98 | ||
| 99 | $this->forgetCachedPermissions(); |
|
| 100 | ||
| 101 | return $this; |
|
| 102 | } |
|
| 103 | ||
| 104 | /** |
|
| 105 | * Revoke the given role from the model. |
|