Caffeinated\Menus\Builder::__call PHP Method

__call() public method

Dynamic search method against a menu attribute.
public __call ( string $method, array $args ) : Item | boolean
$method string
$args array
return Item | boolean
    public function __call($method, $args)
    {
        preg_match('/^[W|w]here([a-zA-Z0-9_]+)$/', $method, $matches);
        if ($matches) {
            $attribute = Str::lower($matches[1]);
        } else {
            throw new BadMethodCallException('Call to undefined method ' . $method);
        }
        $value = $args ? $args[0] : null;
        $recursive = isset($args[1]) ? $args[1] : false;
        if ($recursive) {
            return $this->filterRecursively($attribute, $value);
        }
        return $this->items->filter(function ($item) use($attribute, $value) {
            if (isset($item->data[$attribute]) && $item->data[$attribute] == $value) {
                return true;
            }
            if (!property_exists($item, $attribute)) {
                return false;
            }
            if ($item->{$attribute} == $value) {
                return true;
            }
            return false;
        })->values();
    }