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

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