Lavary\Menu\Builder::add PHP Method

add() public method

Adds an item to the menu
public add ( string $title, $options = '' ) : Lavary\Menu\Item
$title string
return Lavary\Menu\Item $item
    public function add($title, $options = '')
    {
        $id = isset($options['id']) ? $options['id'] : $this->id();
        $item = new Item($this, $id, $title, $options);
        $this->items->push($item);
        return $item;
    }

Usage Example

Beispiel #1
0
 /**
  * Build a level of menu
  * 
  * @param  array  $config 
  * @param  Lavary\Menu\Builder $menu
  * @param  string|null $namespace
  * @return void
  */
 protected function build(array $config, Builder $menu, $namespace = null)
 {
     foreach ($config as $key => $value) {
         $route = null;
         if (isset($value['route'])) {
             $route = ['route' => $value['route']];
         }
         if (isset($value['url'])) {
             $route = $value['url'];
         }
         if ($namespace) {
             $menu->get(strtolower($namespace))->add($key, $route)->data('public', $value['public']);
         } else {
             $menu->add($key, $route)->data('public', $value['public']);
         }
         if (isset($value['children'])) {
             $this->build($value['children'], $menu, $key);
         }
     }
 }