Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$menu->add method #29

Open
drparham opened this issue Jun 22, 2015 · 2 comments
Open

$menu->add method #29

drparham opened this issue Jun 22, 2015 · 2 comments

Comments

@drparham
Copy link

When trying to create a menu item using the $menu->add method with the following:

$menu->add([
        'route' => 'dashboard.settings',
        'title' => 'Settings',
        'icon'  => 'fa fa-cog',
        'attributes' => [
            'target' => '_blank'
        ],
        'order' => 5
    ]);

option I get an error:
Route [d] not defined.
The Menu seems to be looking for the first character of the named route instead of the entire named route. Works fine if i switch to 'url' => 'path/name' like so:

$menu->add([
        'url' => 'dashboard/settings',
        'title' => 'Settings',
        'icon'  => 'fa fa-cog',
        'attributes' => [
            'target' => '_blank'
        ],
        'order' => 5
    ]);

Is this an error with the menu system, or an error in the documentation? How can i used named routes with the add method? As far as i can tell the only way to add an icon to a menu item is via the $menu->add method.

@gravitano
Copy link
Member

You need to use array for route action.

$menu->add([
        'url' => ['dashboard/settings'],
        'title' => 'Settings',
        'icon'  => 'fa fa-cog',
        'attributes' => [
            'target' => '_blank'
        ],
        'order' => 5
    ]);

I would improve this feature in next release. Thanks!

@drparham
Copy link
Author

If i change it to an array like this:

$menu->add([
            'route' => ['dashboard.settings'],
            'title' => 'Settings',
            'icon'  => 'fa fa-cog',
            'attributes' => [
            'target' => '_blank'
            ],
            'order' => 5
        ]);

I get an error in: MenuItem.php line 268:

return !empty($this->route) ? route($this->route[0], $this->route[1]) : url($this->url);

If i add an empty array to the route array like so:

       $menu->add([
            'route' => ['dashboard.settings',[]],
            'title' => 'Settings',
            'icon'  => 'fa fa-cog',
            'attributes' => [
            'target' => '_blank'
            ],
            'order' => 5
        ]);

That fixes the problem. If I add something besides an array it adds the ? to the end of the URI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants