| @@ 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. |
|
| @@ 233-250 (lines=18) @@ | ||
| 230 | * |
|
| 231 | * @return $this |
|
| 232 | */ |
|
| 233 | public function givePermissionTo(...$permissions) |
|
| 234 | { |
|
| 235 | $permissions = collect($permissions) |
|
| 236 | ->flatten() |
|
| 237 | ->map(function ($permission) { |
|
| 238 | return $this->getStoredPermission($permission); |
|
| 239 | }) |
|
| 240 | ->each(function ($permission) { |
|
| 241 | $this->ensureModelSharesGuard($permission); |
|
| 242 | }) |
|
| 243 | ->all(); |
|
| 244 | ||
| 245 | $this->permissions()->saveMany($permissions); |
|
| 246 | ||
| 247 | $this->forgetCachedPermissions(); |
|
| 248 | ||
| 249 | return $this; |
|
| 250 | } |
|
| 251 | ||
| 252 | /** |
|
| 253 | * Remove all current permissions and set the given ones. |
|