Пример #1
0
 /**
  * Find and return the given menu collection.
  *
  * @param  string  $key
  * @return \Caffeinated\Menus\Collection
  */
 public function get($key)
 {
     return $this->collection->get($key);
 }
Пример #2
0
 /**
  * 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;
 }