Code Duplication    Length = 18-18 lines in 2 locations

src/Traits/HasPermissions.php 1 location

@@ 21-38 (lines=18) @@
18
     *
19
     * @return $this
20
     */
21
    public function givePermissionTo(...$permissions)
22
    {
23
        $permissions = collect($permissions)
24
            ->flatten()
25
            ->map(function ($permission) {
26
                return $this->getStoredPermission($permission);
27
            })
28
            ->each(function ($permission) {
29
                $this->ensureModelSharesGuard($permission);
30
            })
31
            ->all();
32
33
        $this->permissions()->saveMany($permissions);
34
35
        $this->forgetCachedPermissions();
36
37
        return $this;
38
    }
39
40
    /**
41
     * Remove all current permissions and set the given ones.

src/Traits/HasRoles.php 1 location

@@ 80-97 (lines=18) @@
77
     *
78
     * @return $this
79
     */
80
    public function assignRole(...$roles)
81
    {
82
        $roles = collect($roles)
83
            ->flatten()
84
            ->map(function ($role) {
85
                return $this->getStoredRole($role);
86
            })
87
            ->each(function ($role) {
88
                $this->ensureModelSharesGuard($role);
89
            })
90
            ->all();
91
92
        $this->roles()->saveMany($roles);
93
94
        $this->forgetCachedPermissions();
95
96
        return $this;
97
    }
98
99
    /**
100
     * Revoke the given role from the model.