Code Duplication    Length = 22-26 lines in 2 locations

src/Traits/HasRoles.php 1 location

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

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.