Silvanite / novatoolpermissions

Laravel Nova Permissions Tool (User, Roles and Permissions / Access Control (ACL))
MIT License
101 stars 33 forks source link

Call to a member function contains() on null after updating nova #18

Closed atmacoder closed 6 years ago

atmacoder commented 6 years ago

`/home /kpvrp56vtcsd /public_html /site.com /vendor /silvanite /brandenburg /src /Traits /HasRoles.php /**

atmacoder commented 6 years ago

sorry it is ok now)) just space between if(is_string($role)) { return $this->roles()->attach(Role::where('slug', $role)->first()); }

pitylee commented 2 years ago

This should fix the problem:

    /**
     * Determine if any of the assigned roles to this user
     * have a specific permission
     *
     * @param string $permission
     * @return boolean
     */
    public function hasRoleWithPermission($permission)
    {
        return !is_null($this->roles()->count()) ? $this->roles()->get()->contains(function ($role) use ($permission) {
            return $role->getPermissions()->get()->contains('permission_slug', $permission);
        }) : null;
    }