/** * Find and return the given menu collection. * * @param string $key * @return \Caffeinated\Menus\Collection */ public function get($key) { return $this->collection->get($key); }
/** * Filter menu items recursively. * * @param string $attribute * @param mixed $value * * @return Collection */ public function filterRecursively($attribute, $value) { $collection = new Collection(); $this->items->each(function ($item) use($attribute, $value, &$collection) { if (!property_exists($item, $attribute)) { return $false; } if ($item->{$attribute} == $value) { $collection->push($item); if ($item->hasChildren()) { $collection = $collection->merge($this->filterRecursively($attribute, $item->id)); } } }); return $collection; }