Code Duplication    Length = 18-18 lines in 2 locations

src/Traits/HasRoles.php 1 location

@@ 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.

src/Traits/HasPermissions.php 1 location

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