@@ 62-79 (lines=18) @@ | ||
59 | * @return $this |
|
60 | * @throws GuardDoesNotMatch |
|
61 | */ |
|
62 | public function givePermissionTo(...$permissions) |
|
63 | { |
|
64 | $permissions = collect($permissions) |
|
65 | ->flatten() |
|
66 | ->map(function ($permission) { |
|
67 | return $this->getStoredPermission($permission); |
|
68 | }) |
|
69 | ->each(function ($permission) { |
|
70 | $this->ensureModelSharesGuard($permission); |
|
71 | }) |
|
72 | ->all(); |
|
73 | ||
74 | $this->permissions()->saveMany($permissions); |
|
75 | ||
76 | $this->forgetCachedPermissions(); |
|
77 | ||
78 | return $this; |
|
79 | } |
|
80 | ||
81 | /** |
|
82 | * Remove all current permissions and set the given ones. |
@@ 63-80 (lines=18) @@ | ||
60 | * |
|
61 | * @return array|Role|string |
|
62 | */ |
|
63 | public function assignRole(...$roles) |
|
64 | { |
|
65 | $roles = \collect($roles) |
|
66 | ->flatten() |
|
67 | ->map(function ($role) { |
|
68 | return $this->getStoredRole($role); |
|
69 | }) |
|
70 | ->each(function ($role) { |
|
71 | $this->ensureModelSharesGuard($role); |
|
72 | }) |
|
73 | ->all(); |
|
74 | ||
75 | $this->roles()->saveMany($roles); |
|
76 | ||
77 | $this->forgetCachedPermissions(); |
|
78 | ||
79 | return $roles; |
|
80 | } |
|
81 | ||
82 | /** |
|
83 | * Revoke the given role from the model. |