lavary / laravel-menu Goto Github PK
View Code? Open in Web Editor NEWA quick way to create menus in Laravel
License: MIT License
A quick way to create menus in Laravel
License: MIT License
I use Bootstrap 3, but have problem when render (display don't correct).
..............
<div class="collapse navbar-collapse">
{{ $MenuName->asBootstrap() }}
</div>
..............
Currently it will use the class "active" if an element is active as defined in
Menu/Item.php on line 354:
$this->attributes['class'] = Builder::formatGroupClass(array('class' => 'active'), $this->attributes);
However many template use a different class, for example nav-active
Could you please add a config value to customize it?
Thank you very much.
Item->data
is not initialized. So, when using $menu->add(...)->data(array(...associative...));
it errors because it can't merge null with the associative array.
https://github.com/lavary/laravel-menu/blob/master/src/Lavary/Menu/Item.php#L266
P.S. Unless you couldn't tell, I really like this package you have put together. :) Just reporting kinks as I work through the system.
I tried to add menu with action but always return Exception with message "Route [HomeController@getIndex] not defined." though its already defined.
This problem occurs when I put menu definition outside routes.php, I put it in app/menus.php which actually loaded by start/global.php
I want to create sub menu in sub menu.
Pm help me.
I was in need to remove this package. I tried with the command composer remove lavary/laravel-menu
but throwing error:
{"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","message":"Class 'Lavary\\Menu\\ServiceProvider' not found","file":"\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/ProviderRepository.php","line":157}}Script php artisan clear-compiled handling the post-update-cmd event returned with an error
Hey because you are superman.. =)
Is there a cleaner better way to achieve this:
Menu::make('loginNav', function($menu){
$menu->add(trans('login.login'), array('route' => 'login'))
->meta('loggedIn', false);
$menu->add(trans('login.register'), array('route' => 'register'))
->meta('loggedIn', false);
$menu->add(trans('login.logout'), 'todo')
->meta('loggedIn', true);
$menu->add('Name', 'services')
->meta('loggedIn', true);
})->filter(function($item) {
if($item->meta('loggedIn')) {
return Sentry::check();
}
return !Sentry::check();
});
PS: i like opening issues for you =) haha
I think that you should use static method when rending
{{ Menu::render('menu_name')->asUl() }}
Why?
I was looking for a menu for Laravel 5 and I found this one.
Unfortunately the documentation and the branches do not match, so after a few hours making this work I had to quit.
Can anyone point me to the correct installation for the latest updated and working package?
I also want to encourage you to review the documentation because many of the examples do not work (anymore), and this will confuse of course everyone wanting to use it.
This will be a pity, seen the work has been made to develop it
Any help will be appreciated.
Cheers
Franco
Can I set somehow active state for specific url? I mean, if I click on "articles" in menu, then I choose an article, which url is like "/this-is-the-title/56" , so by default laravel-menu won't find the active menu with the help of current url, but the article contained by the articles menu item, so that should be active in my case.
Thanks
I need a set class for sub menu ul
<ul>
<li class="navbar navbar-home" id="home"><a href="/">Home</a></li>
<li data-role="navigation" class="navbar navbar-about dropdown"><a href="#">About</a>
// Need to set <ul class='submenu'>
<ul>
<li><a href="#>Who we are?</a></li>
<li><a href="#">What we do?</a></li>
</ul>
</li>
<li><a href="services">Services</a></li>
<li><a href="contact">Contact</a></li>
</ul>
I may miss something, but I can't seem to find such method.
When calling it from my code there is no output, and I can't seem to understand what it's supposed to do. I'm curious because I'm using bootstrap.
Is it possible to specify a menu depth?
Like Menu::get('mainnav')->maxdepth(1) for showing only the top navigation.
Is there a way i can get all menu's i made with Menu::make
these are the Builder.php Classes i think..?
In builder.php line 510...
https://github.com/lavary/laravel-menu/blob/master/src/Lavary/Menu/Builder.php#L510
It has $items .= "<{$item_tag}{$this->attributes($item->attr)}>";
It may need to be $items .= "<{$item_tag}{$this->attributes($item->attributes)}>";
When I call $item->active();
it adds class => active
to the attributes property. So, as it stands, $item->attr
won't pull the active class for the list item.
Hi,
How to get the current parameters in routes.php?
for example. I'm in project/1 and I want a sidemenu where the link project/1/locations is defined.
I've got this:
Route::resource('project', 'ProjectsController', array('only' => array('show')));
Route::resource('project.locations', 'LocationsController');
Menu::make('sidemenu-project', function($menu) {
$menu->add('Locaties', array('route' => 'project.locations.index','{project?}'))->data('id',1)->prepend(' ');
});
the item.blade.php should use this:
<li{!! Lavary\Menu\Builder::attributes($item->divider) !!}></li>
instead of
<li{{ Lavary\Menu\Builder::attributes($item->divider) }}></li>
Is there a way that I'm missing to create a link to # as in literally <a href="#">
as currently using 'url' => '#'
ends up as http://mydomain.com/#
because $link->url()
calls $this->url->to($prefix . '/' . $url, array(), $secure)
which then /# becomes the current site. This can cause different behavior than simply #.
Why does builder->add use collection->push?
http://laravel.com/api/source-class-Illuminate.Support.Collection.html#_push
This means each time you add an item, it's being prepended to the menu.
$menu->add(...1...)
$menu->add(...2...)
Logically if you add two items, you'd expect the first item to be first. But, using push means the first item is last, and the second item is first.
It seems like the add function should simply call $this->items[] = $item;
so that they're added in order.
Perhaps you were looking for a function to add an item to the collection's items array and only saw push? Since it implements ArrayAccess, you can simply use $col[] = ...;
to append an item to the array, rather than pushing/unshifting it.
After hitting issues with the facade (https://github.com/lavary/laravel-menu/issues?q=is%3Aopen+is%3Aissue) I tried calling the the code below and received an error. I've seen similar errors in the past which has been down to Laravel having issues with multiple config files (on certain systems at random). The package/service provider/facade are all installed as per the docs, I'm running windows/WAMP.
My code:
$menu = new Menu;
$menu->make('MyNavBar', function($menu){
$menu->add('Home', array('route' => 'home.page'));
});
The error:
Undefined index: default
here: โฆ\vendor\lavary\laravel-menu\src\Lavary\Menu\Menu.php 63
It seems as though the config is not loading, I've tried dumping the $options array from a line 56 in Menu.php and this returns:
array (size=0)
empty
I know i could publish the views and overwrite them, but anyway an option would be nice.
Reason: you're menu is like default rendered on the left side in the navbar, but what if i want to add other stuff like login, or second menu in the right side of the navbar..
Hi,
Here's my scenario, in my package i've created file menus.php
<?php
Menu::make('adminMenu', function($menu) {
$menu->add('Dashboard', route('admin.home'))->prepend('<i class="fa fa-dashboard fa-fw"></i> ');
$menu->add('Settings', 'settings')->prepend('<i class="fa fa-cogs fa-fw"></i> ');
// sample dropdown
$menu->add('Dropdown', '#')
->prepend('<i class="fa fa-sitemap fa-fw"></i>')
->append(' <span class="fa arrow"></span>');
$dropdown = $menu->get('dropdown');
$dropdown->add('Second Level Item', '#');
$dropdown->add('Second Level Item', '#');
$dropdown->add('Third Level', '#')->append(' <span class="fa arrow"></span>');
$thirdLevel = $menu->get('thirdLevel');
$thirdLevel->add('Third Level Item', '#');
$thirdLevel->add('Third Level Item', '#');
$thirdLevel->add('Third Level Item', '#');
});
and load them from my ServiceProvider
inside boot()
method by calling
// include package menus.php
include __DIR__ . '/../../menus.php';
Then call it as usually from my view, but then i get this error
Seems like in boot() method, Menu package not loaded yet.. so my question how to make this work? do you have idea where to save menu builder instead using menus.php like i did?
Here's my files stucture
Thanks
Hi. I create a custom template, but still cant reproduce needed markup:
<ul class="sidebar-menu">
<li class="active">
<a href="index.html">
<i class="fa fa-dashboard"></i> <span>Dashboard</span>
</a>
</li>
<li>
<a href="pages/widgets.html">
<i class="fa fa-th"></i> <span>Widgets</span> <small class="badge pull-right bg-green">new</small>
</a>
</li>
<li class="treeview">
<a href="#">
<i class="fa fa-bar-chart-o"></i>
<span>Charts</span>
<i class="fa fa-angle-left pull-right"></i>
</a>
<ul class="treeview-menu">
<li><a href="pages/charts/morris.html"><i class="fa fa-angle-double-right"></i> Morris</a></li>
<li><a href="pages/charts/flot.html"><i class="fa fa-angle-double-right"></i> Flot</a></li>
<li><a href="pages/charts/inline.html"><i class="fa fa-angle-double-right"></i> Inline charts</a></li>
</ul>
</li>
<li class="treeview">
<a href="#">
<i class="fa fa-laptop"></i>
<span>UI Elements</span>
<i class="fa fa-angle-left pull-right"></i>
</a>
<ul class="treeview-menu">
<li><a href="pages/UI/general.html"><i class="fa fa-angle-double-right"></i> General</a></li>
<li><a href="pages/UI/icons.html"><i class="fa fa-angle-double-right"></i> Icons</a></li>
<li><a href="pages/UI/buttons.html"><i class="fa fa-angle-double-right"></i> Buttons</a></li>
<li><a href="pages/UI/sliders.html"><i class="fa fa-angle-double-right"></i> Sliders</a></li>
<li><a href="pages/UI/timeline.html"><i class="fa fa-angle-double-right"></i> Timeline</a></li>
</ul>
</li>
</ul>
How send icon title for "i" element before item "title"?
My custom template:
@foreach($items as $item)
<li@lm-attrs($item) @if($item->hasChildren()) class="treeview" @endif @lm-endattrs>
<a href="{{ $item->url() }}">
<span>{{ $item->title }}</span>
@if($item->hasChildren()) <i class="fa fa-angle-left pull-right"></i> @endif
</a>
@if($item->hasChildren())
<ul class="treeview-menu">
@include('admin.blocks.sidebar-menu-items', array('items' => $item->children()))
</ul>
@endif
</li>
@endforeach
I Lavary,
I noticed that you have extended the "active" function with the pattern recognition but you've done that only for the master branch which is only compatible with Laravel 5.
Could you please add this possibility to the 1.4 branch for the Laravel 4 users ?
Thanks for your great job and sorry for my broken english.
Sorry for spamming you =)
but if i do:
Menu::make('mainNav', function($menu){
$menu->add('Home', '');
$menu->add('About', 'about');
$menu->add('services', 'services');
$menu->add('Contact', 'contact');
});
Menu::make('loginNav', function($menu){
$menu->add('Login', '');
$menu->add('Logout', 'about');
$menu->add('Name', 'services');
});
I get Call to a member function asBootstrap() on a non-object
am i doing something wrong?
Is it compatible with Laravel 5.1? I added it just now , but its giving me an exception
Hi, when I'm trying to add menu to view I'm getting this error:
Array to string conversion in /vendor/lavary/laravel-menu/src/Lavary/Menu/Builder.php line 557
here is my code:
Menu::make('menu_front', function ($menu) {
$menu->add('Login', 'login');
if(Auth::check() && Auth::user()->isAdmin()) $menu->add('Admin', 'admin');
});
and
{!! Menu::get('menu_front')->asUl() !!}
or
{!! $menu_front->asUl() !!}
I use latest version 1.5.1 and laravel 5.1.10
PS: Laravel from v5.1 moved to spaces indents, I think it's good to change coding style here as well.
I have a resource 'customers'. I created a menu with a link in it that links to CustomersController@index
. When I click a link in my customer.index
route which links to an edit page (customer.edit
) the customers
menu item doesn't get highlighted.
Would it be possible to make a menu-item also active when it matches the current url even if the current url has some extra paths? For example in this case:
/customers
/customers/2
Or maybe add an option to a new menu item to match by regex of match by controller?
Hi @lavary , thx for your package.
When i use my custom menu blade, how to know the item is active?
I need to add some active class in html.
Forgive my broken english. ๐ข
Hello, and thanks you for such great packaged!
But I can't find any easy way to build breadcrumbs based on active path.
Let's say we have following menu structure:
$menu->add('Dashboard', ['action' => 'DashboardController@showDashboardPage']);
$menu->add('Push Notifications');
$menu->pushNotifications->add('Overview', ['action' => 'Controller@ActionA']);
$menu->pushNotifications->add('Create Campaign', ['action' => 'Controller@Action B']);
So I want to build breadcrubms like so:
Home > Dashboard
.Home > Push Notifications > Overview
.Home > Push Notifications > Create Campaign
.I'm pretty sure I've read all documentation, but I can't find how to do this right now. Is this possible?
Hi,
I'm trying to create a menu, according to the documentation, but always obtain the following error : "Array to string conversion" when i'm trying to print it on the view.
I tried to access the menu with the asUl method {!! Menu::get('MyNavBar')->asUl() !!} and with the custom menu template in a separate view but always got this issue.
Laravel version is 5.1.
A little help would be appreciated :)
Thank in advance.
Hi
I'm running Laravel 4.2.3 and after adding the lavary\laravel-menu package and registering the alias and service provider I get the following error with simply adding this to my route.php
Menu::make('MyNavBar', function($menu){
$menu->add('Home', '');
});
Argument 3 passed to Lavary\Menu\Menu::__construct() must be an instance of Illuminate\View\Environment, instance of Illuminate\View\Factory given, called in /webroot/vendor/lavary/laravel-menu/src/Lavary/Menu/ServiceProvider.php on line 32 and defined
When I try it on Laravel 4.1.30 it works just fine without any errors. Is there anything I can try to resolve this work on 4.2?
Thanks
Roy
$menu->add('Companies', 'companies');
$menu->companies->add('New', 'companies/new');
$menu->companies->add('All', 'companies/all');
$menu->add('Users', 'users');
$menu->users->add('New', 'users/new');
$menu->users->add('All', 'users/all');
$menu->all->link->['foo' => 'bar']);
The title property is used to define the item object.
In the above use case, the item's link attribute is setting for both companies->all and users->all.
Is this intended, a bug, or am I blatantly missing something?
Call to undefined method Lavary\Menu\Item::title()
Why?
Is the library stable?
It would be nice to have the ability to show the menu horizontal. I have an application that I am rewriting in Laravel and need to have the menu go across the top. The menu system I have uses a hidden table for the layout but there maybe a better way to do it. I looked at doing it using CSS but with the list tags, I am not sure how a horizontal menu would work.
Regards,
Ken
Would be interesting to set the id of the item manually, it would facilitate the creation of submenus using the method find, so for example, I could set the id of the item by the same id of a record in a database table.
For example:
$menu->add("Item title", "Item ID", $options);
In this case the id of the item could be optional, if not passed, would be set automatically as currently occurs.
Menu::make('LandingPageMenu', function ($menu) {
$menu->add('Services', ['url' =>'services', 'class' => 'dropdown']);
$menu->services->add('link1')->link->href('#');
$menu->services->add('link2')->link->href('#');
$menu->services->data('permission', 'services_permission');
})->filter(function ($item) {
$permissions = ['services_permission'];
if (in_array($item->data('permission'), $permissions)) {
return true;
}
return false;
});
Maybe it is a silly question i need some directions here.
I added to Services link a permission but sub-links aren't displayed in the menu.
Is there a way to inherit the permissions from the main link or do i need to set up for each sub-link?
Hey,
Nice work on this package! One thing is a bit odd though. The readme advices people to include the setting up of your menu in your routes.php
or in global.php
, but to me that sounds like overkill. It seems to me this would be slightly better:
If you have some master template, put in the top
<?php require app_path() . '/views/menubuilder.php'; ?>
There you build your menu. This way you won't unneccesarily pollute API calls with your menu building which you'll never use in those calls.
didn't search for it, but anyway a built in solution for current or active menu-item would be great...
An really this one is the best menu Builder for Laravel out there !! Thanks for making it =)
I've installed the latest package (using composer), and have added the service provider and facade as per the docs (including to my local config file. When I run the following code, I get the error listed below:
Menu::make('MyNavBar', function($menu){
$menu->add('Home', array('route' => 'home.page'));
});
error:
Non-static method Lavary\Menu\Menu::make() should not be called statically, assuming $this from incompatible context
The error links to the first line of the code above.
It seems that the facade isn't working quite like it should, I've had a look but I'm not familiar enough with creating facades to see an issue.
I'm working on windows/WAMP if that makes any difference?
I have the following routes:
Route::group(array( 'prefix' => Localization::setLocale(), 'before' => 'auth'), function()
{
Route::get('/', ['as' => 'home', 'uses' => 'indexController@index']);
Route::get('lorem/', ['as' => 'business-index', 'uses' => 'LoremController@index']);
Route::get('lorem/{slug}-{id}', ['as' => 'lorem-page', 'uses' => 'LoremController@pageView'])
->where(['slug' => '[a-z0-9-]+', 'id' => '[0-9]+']);
Route::get('ipsum', ['as' => 'ipsum-index', 'uses' => 'IpsumController@index']);
});
and the menu:
Menu::make('loremipsum', function($menu){
$menu->add('index', ['route' => 'home']);
$menu->add('lorem', ['route' => 'lorem-index']);
$menu->add('ipsum, ['route' => 'ipsum-index']);
Event::fire('menuTop', $menu);
});
The prefix comes from the laravel-localization package. (can prefix en
, nl
, de
et cetera)
Now when visiting mysite.dev/en/lorem
, the index link also lights up! What am I doing wrong?
I have a language switcher to URL/en/ and that language switcher should never be active, not should its parent for example.
Maybe an implemenation of neverActive()
would be an option?
on my mac it work's totaly fine but on my pc the menu dont include.
also the bootstrap menu Settings
Config::get('laravel-menu::views.bootstrap-items')is null an
@include('laravel-menu::bootstrap-navbar-items', array('items' => $MainMenuRight->roots()))
it also don't work and in both cases it don't create's an new view Cache in storage.
hey, i think you miss write the docs page at prefixing
so here is the code
add('Home', array('route' => 'home.page', 'class' => 'navbar navbar-home', 'id' => 'home')); $menu->add('About', array('url' => 'about', 'class' => 'navbar navbar-about dropdown')); // URL: /about $menu->group(array('prefix' => 'about') function($m){ ``` $about->add('Who we are?', 'who-we-are'); // URL: about/who-we-are $about->add('What we do?', 'what-we-do'); // URL: about/what-we-do ``` } $menu->add('Contact', 'contact'); }); ?>and it should be
add('Home', array('route' => 'home.page', 'class' => 'navbar navbar-home', 'id' => 'home')); $menu->add('about', array('url' => 'about', 'class' => 'navbar navbar-about dropdown')); // URL: /about $menu->group(array('prefix' => 'about'), function($m){ ``` $m->about->add('Who we are?', 'who-we-are'); // URL: about/who-we-are $m->about->add('What we do?', 'what-we-do'); // URL: about/what-we-do ``` }); $menu->add('Contact', 'contact'); }); ?>thank you
Hi,
I must say that this is an awesome library for laravel. I wanted to create a menu that will result to:
<div class="panel panel-default list-group">
<a class="list-group-item collapsed" data-toggle="collapse" data-parent="#accordion-nav" href="#project"><span
class="glyphicon glyphicon-tag"></span>Projects<span
class="glyphicon glyphicon-chevron-updown pull-right"></span></a>
<div id="project" class="panel-collapse collapse">
<a href="#" class="list-group-item">Submenu 1</a>
<a href="#" class="list-group-item">Submenu 2</a>
<a href="#" class="list-group-item">Submenu 3</a>
<a href="#" class="list-group-item">Submenu 4</a>
</div>
</div>
<div class="panel panel-default list-group">
<a class="list-group-item collapsed" data-toggle="collapse" data-parent="#accordion-nav" href="#account"><span
class="glyphicon glyphicon-folder-open"></span>My Account<span
class="glyphicon glyphicon-chevron-updown pull-right"></span></a>
<div id="account" class="panel-collapse collapse">
<a href="#" class="list-group-item">Submenu 1</a>
<a href="#" class="list-group-item">Submenu 2</a>
<a href="#" class="list-group-item">Submenu 3</a>
<a href="#" class="list-group-item">Submenu 4</a>
</div>
</div>
as you can see, we are using bootstrap's accordion and collapse.
so far, here's what I have:
@foreach($items as $item)
<div@lm-attrs($item) @if($item->hasChildren()) class="panel panel-default list-group" @endif data-test="test" @lm-endattrs>
<a href="{{ $item->url }}">{{ $item->title }} </a>
@if($item->hasChildren())
<div id="account" class="panel-collapse collapse">
@include('custom-menu-items', array('items' => $item->children()))
</div>
@endif
</div>
@endforeach
It seems so far from my desired output. Please help!
Thanks!
Generating autoload files
{"error":{"type":"Symfony\Component\Debug\Exception\FatalErrorException","message":"Call to undefined method Lavary\Menu\ServiceProvider::mergeConfigFrom()","file":"C:\xampp\htdocs\nanolarave
l\vendor\lavary\laravel-menu\src\Lavary\Menu\ServiceProvider.php","line":21}}Script php artisan clear-compiled handling the post-update-cmd event returned with an error
Are there any plans to make this package compatible with L5? (Assuming it's not already)
Why do you choose to use certain methods in camelCase and others in snake_case? Is there a particular reason?
public function get_title()
{
return $this->link->get_text();
}
public function hasChilderen()
{
return (count($this->ref->whereParent($this->id))) ? true : false;
}
All the other properties are applied except the url property and it is set in the routes.php file.
This is what i am talking about:
<li @if($item->hasChildren()) class="treeview" @endif>
<a href="{{ $item->url }}">
{{ $item->prepend }}
{{ $item->title }}
{{ $item->append }}
</a>
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.