| @@ 81-98 (lines=18) @@ | ||
| 78 | * |
|
| 79 | * @return $this |
|
| 80 | */ |
|
| 81 | public function assignRole(...$roles) |
|
| 82 | { |
|
| 83 | $roles = collect($roles) |
|
| 84 | ->flatten() |
|
| 85 | ->map(function ($role) { |
|
| 86 | return $this->getStoredRole($role); |
|
| 87 | }) |
|
| 88 | ->each(function ($role) { |
|
| 89 | $this->ensureModelSharesGuard($role); |
|
| 90 | }) |
|
| 91 | ->all(); |
|
| 92 | ||
| 93 | $this->roles()->saveMany($roles); |
|
| 94 | ||
| 95 | $this->forgetCachedPermissions(); |
|
| 96 | ||
| 97 | return $this; |
|
| 98 | } |
|
| 99 | ||
| 100 | /** |
|
| 101 | * Revoke the given role from the model. |
|
| @@ 211-228 (lines=18) @@ | ||
| 208 | * |
|
| 209 | * @return $this |
|
| 210 | */ |
|
| 211 | public function givePermissionTo(...$permissions) |
|
| 212 | { |
|
| 213 | $permissions = collect($permissions) |
|
| 214 | ->flatten() |
|
| 215 | ->map(function ($permission) { |
|
| 216 | return $this->getStoredPermission($permission); |
|
| 217 | }) |
|
| 218 | ->each(function ($permission) { |
|
| 219 | $this->ensureModelSharesGuard($permission); |
|
| 220 | }) |
|
| 221 | ->all(); |
|
| 222 | ||
| 223 | $this->permissions()->saveMany($permissions); |
|
| 224 | ||
| 225 | $this->forgetCachedPermissions(); |
|
| 226 | ||
| 227 | return $this; |
|
| 228 | } |
|
| 229 | ||
| 230 | /** |
|
| 231 | * Remove all current permissions and set the given ones. |
|