Code Duplication    Length = 22-26 lines in 2 locations

src/Traits/HasPermissions.php 1 location

@@ 260-281 (lines=22) @@
257
     *
258
     * @return $this
259
     */
260
    public function givePermissionTo(...$permissions)
261
    {
262
        $permissions = collect($permissions)
263
            ->flatten()
264
            ->map(function ($permission) {
265
                return $this->getStoredPermission($permission);
266
            })
267
            ->filter(function ($permission) {
268
                return $permission instanceof Permission;
269
            })
270
            ->each(function ($permission) {
271
                $this->ensureModelSharesGuard($permission);
272
            })
273
            ->map->id
274
            ->all();
275
276
        $this->permissions()->sync($permissions, false);
277
278
        $this->forgetCachedPermissions();
279
280
        return $this;
281
    }
282
283
    /**
284
     * Remove all current permissions and set the given ones.

src/Traits/HasRoles.php 1 location

@@ 95-120 (lines=26) @@
92
     *
93
     * @return $this
94
     */
95
    public function assignRole(...$roles)
96
    {
97
        $roles = collect($roles)
98
            ->flatten()
99
            ->map(function ($role) {
100
                if (empty($role)) {
101
                    return false;
102
                }
103
104
                return $this->getStoredRole($role);
105
            })
106
            ->filter(function ($role) {
107
                return $role instanceof Role;
108
            })
109
            ->each(function ($role) {
110
                $this->ensureModelSharesGuard($role);
111
            })
112
            ->map->id
113
            ->all();
114
115
        $this->roles()->sync($roles, false);
116
117
        $this->forgetCachedPermissions();
118
119
        return $this;
120
    }
121
122
    /**
123
     * Revoke the given role from the model.