Code Duplication    Length = 22-26 lines in 2 locations

src/Traits/HasPermissions.php 1 location

@@ 251-272 (lines=22) @@
248
     *
249
     * @return $this
250
     */
251
    public function givePermissionTo(...$permissions)
252
    {
253
        $permissions = collect($permissions)
254
            ->flatten()
255
            ->map(function ($permission) {
256
                return $this->getStoredPermission($permission);
257
            })
258
            ->filter(function ($permission) {
259
                return $permission instanceof Permission;
260
            })
261
            ->each(function ($permission) {
262
                $this->ensureModelSharesGuard($permission);
263
            })
264
            ->map->id
265
            ->all();
266
267
        $this->permissions()->sync($permissions, false);
268
269
        $this->forgetCachedPermissions();
270
271
        return $this;
272
    }
273
274
    /**
275
     * Remove all current permissions and set the given ones.

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.