Adldap\Models\Traits\HasMemberOfTrait::inGroup PHP Method

inGroup() public method

Determine if the current model is a member of the specified group(s).
public inGroup ( mixed $group, boolean $recursive = false ) : boolean
$group mixed
$recursive boolean
return boolean
    public function inGroup($group, $recursive = false)
    {
        $memberOf = $this->getGroups([], $recursive);
        $groups = is_array($group) ? $group : [$group];
        foreach ($groups as $group) {
            // We need to iterate through each given group that the
            // model must be apart of, then go through the models
            // actual groups and perform validation.
            $exists = $memberOf->filter(function (Group $parent) use($group) {
                return $this->validateGroup($group, $parent);
            })->count() !== 0;
            if (!$exists) {
                // If the current group isn't at all contained
                // in the memberOf collection, we'll
                // return false here.
                return false;
            }
        }
        return true;
    }