caffeinated / menus Goto Github PK
View Code? Open in Web Editor NEW:pushpin: Menu generator package for the Laravel framework
Home Page: https://caffeinatedpackages.com
:pushpin: Menu generator package for the Laravel framework
Home Page: https://caffeinatedpackages.com
I correct this for you.
$item->icon is correct. $item->data->icon is incorrect!
I appreciate to see these functionality like Route::group() :)
Do you plan something like this ?
$menu = Menu::get('navbar');
$menu->add(trans('kotoba::general.home'), '')->data('order', 1);
I also tried with Laravel's default files.
NOTE: I've been tweeking my L5 install so that it is possible that I have a conflict with my own middleware or something else on my side.
I've got the same error as an previous ticket that was closed with a solution that wasn't the correct one... (Call to undefined method Caffeinated\Menus\Facades\Menu::make())
I installed it by using the "Installation" section within the Menus wiki (https://github.com/caffeinated/menus/wiki/Installation)
Then I commented 'Caffeinated\Menus\MenusServiceProvider' in the config/app.php (providers)
And added 'App\Providers\MenuServiceProvider' to config/app.php (providers)
I created the file MenuServiceProvider.php within App/Providers and used the code from the Wiki (https://github.com/caffeinated/menus/wiki/Quick-Start)
Hi , I am getting this error on my laravel5.0.13 new project.Not sure, this is an issue or my setup fault. Please kindly help.
Argument 3 passed to Caffeinated\Menus\Menu::__construct() must be an instance of Collective\Html\HtmlBuilder, instance of Illuminate\Html\HtmlBuilder given, called in D:\www\laravel-5-boilerplate\vendor\caffeinated\menus\src\Caffeinated\Menus\MenusServiceProvider.php on line 47 and defined
I've got a menu at the top of the site and want the children to be show on a sidebar.
Is it possible to show the children only?
lets say i have this menu:
Menu::make('main', function ($menu) {
$menu->add('Client', 'client')->prepend('<i class="fa fa-suitcase"> </i> ');
$menu->client->add('Insurance', '/client/insurance');
now i have a bootstrap list-group element in my design..
i would like to show the subitems in this list group..somethin like this:
if(currentmenu->hasChilds)
foreach($childs as $item){
{{ link for submenu item}}
}
any ideas or hints?
Good evening,
how can I add a new menu item to an existing menu instance within the controller ?
Sorry for my bad english. I'm German.
Greetings,
I've copy and pasted each step from the Wiki pages "Installation" & "Getting Started". As soon as I add App\Providers\MenuServiceProvider
to my list of providers in config/app.php
I get "Call to undefined method Caffeinated\Menus\Facades\Menu::make()".
Have tried twice with fresh L5 installations to no avail.
Greetings, you may want to upgrade your current Readme installation instructions. You'll need "caffeinated/menus": "1.0.*@dev"
in composer.json
. On the current instructions, once I added the service provider & facade I would receive an error that the SP doesn't exist. Once I changed it the require to "caffeinated/menus": "1.0.*@dev"
and ran composer update
everything loaded up fine.
Hello there,
how would I add a route to the menu, so that the active state on the parent is automatically set.
The route has a {uuid}
at the end and generates urls like this
infrastructure/vms/7de30cf6-3773-4818-8e35-ca623d301e96
and is defined in my routes.php like so
Route::get('/vms/{uuid}', ['as'=>'infrastructure.vms.single']);
How can I get only active state for list element ?
Hello,
I want to create a breadcrumb with your menu plugin.
Can I do this easily ?
Greetings.
Well, probably not that much of and edge issue if combined with your module package.
In my main MenuServiceProvider I have:
// navbar menu
Menu::make('navbar', function($menu) {
//
});
Then in a module I have:
// navbar menu
$menu = Menu::get('navbar');
$menu->add('Profiles', 'profiles');
This works for multiple modules.
However the issue I'm having is with trying to get a module menu to over ride the module ordering ... I haven't checked but I'm guess is that the module order is what sets the default for the menus.
I tried:
in my main MenuServiceProvider:
// navbar menu
Menu::make('navbar', function($menu) {
//
})->sortBy('order');
Then in the module menu provider:
// navbar menu
$menu = Menu::get('navbar');
$menu->add('Profiles', 'profiles')->data('order', 0); // tried with 1 too
But another module that has a higher order rank is still being placed first.
I probably just send all this to a db table and create them there but I'm still working on understanding.
in my MenuServiceProvider I tried:
public function boot()
{
// navbar menu
if ( (Auth::user()->can('manage_admin')) || (Auth::user()->can('manage_shisan')) ) {
$menu = Menu::get('navbar');
...
}}
and end up with the error:
Call to a member function can() on a non-object
I was wondering if there is a way to prevent menus from showing based on user permissions.
arigatou~~~!
After using a similar approach as stated in #26, I'm now one step away from my desired solution.... ;-)
If there are items that are not allowed, they will be removed from the navigation, but any remaining submenus that no longer have any items, are still displayed....
Would be very nice to have some sort of clean-up possibility to remove all items without children and without an link.
Hi,
a little question:
How can I get only the active menu point ?
Is there a function ?
There have been numerous issues created around the automatic active-state detection (#25, #32, #42, and #43). This issue will replace all the other open issues to keep things consolidated in one location.
The active-state detection does not take into consideration dynamic URI segments that may be attributed to the menu item. Below we'll look at an example.
We have a menu defined as follows:
Menu::make('example', function($menu) {
$menu->add('Blog', '#');
$menu->blog->add('Manage Posts', 'admin/blog');
$menu->blog->add('Write New Post', 'admin/blog/create');
});
The following URI's trigger the active state as defined:
URI | Triggers | Should Trigger |
---|---|---|
admin/blog |
Blog and Manage Posts |
Blog and Manage Posts |
admin/blog/create |
Blog and Write New Post |
Blog and Write New Post |
admin/blog/edit/1 |
N/A |
Blog |
Hello!
I have currently one url e.g. "backend/".
All links in this layout will load bis ajax (e.g. backend/news)
The menu is definied over your add on.
How can I set here the link how is active ?
Greetings from Germany.
Hello again. The problem is that menu Items use Russian(non-latin symbols) and I can not add sub-items to such. Is there a solution to that problem?
Hi there
route:list
Shows me that I have a named route called
infrastructure.index
It tells me that I do not have a route named
infrastructure.index
when I'm following your instructions in de wiki.
Have you encountered such an problem before?
Hello,
is there any way to manually set the active link?
I have an item called "VPN" which points to /vpns to show a list of VPNs. But when I visit /vpns/create the link will not be active.
if anybody reads this:
Try doing
php artisan route:clear
๐ ๐ ๐ ๐ ๐ ๐ ๐ ๐ ๐ ๐
Would be nice to parse menu with active element (current link).
Didn't find it in wiki or code.
hmmm, this doesn't seem possible.
->add('view profile', 'profiles'. Auth::user()->id )
Or am I doing something wrong again?
Hello,
I want to generate the menu items from a database table.
Currently I have the following implementation:
Database
Illuminate\Database\Eloquent\Collection Object
(
[items:protected] => Array
(
[0] => App\Modules\Cms\Entities\NavigationAdmin Object
(
[table:protected] => navigation_admin
[fillable:protected] => Array
(
[0] => title
[1] => options
[2] => parent_id
)
[connection:protected] =>
[primaryKey:protected] => id
[perPage:protected] => 15
[incrementing] => 1
[timestamps] => 1
[attributes:protected] => Array
(
[id] => 1
[title] => Dashboard
[options] => {"icon":"home","order":"10","role":"admin"}
[parent_id] =>
[created_at] => 2015-06-04 11:29:34
[updated_at] => 2015-06-04 11:29:34
)
[original:protected] => Array
(
[id] => 1
[title] => Dashboard
[options] => {"icon":"home","order":"10","role":"admin"}
[parent_id] =>
[created_at] => 2015-06-04 11:29:34
[updated_at] => 2015-06-04 11:29:34
)
[relations:protected] => Array
(
)
[hidden:protected] => Array
(
)
[visible:protected] => Array
(
)
[appends:protected] => Array
(
)
[guarded:protected] => Array
(
[0] => *
)
[dates:protected] => Array
(
)
[casts:protected] => Array
(
)
[touches:protected] => Array
(
)
[observables:protected] => Array
(
)
[with:protected] => Array
(
)
[morphClass:protected] =>
[exists] => 1
)
)
)
Menu File
use App\Modules\Cms\Entities\NavigationAdmin;
Menu::make('backend', function($menu) {
$items = NavigationAdmin::all();
foreach($items as $item) {
$menu->add($item->title, '#');
if ( isset($item->options) ) {
$options = json_decode($item->options);
$title = camel_case($item->title);
$menu->$title->data([
'order' => $options->order,
'role' => $options->role
]);
}
}
});
After I doing this I will check menu via dd method and all seems okay.
But when I try to get the menu items it load and load and never stops.
Can u help me whats wrong ?
Played around with this about but haven't gotten the ability to allow multiple modules to add to the menu.
It does work for a single module but it's first come first served.
Or ... is this a typical me mistake ๐
sortBy does not sort.
I tried the exact example from the wiki but the output is not sorted by the 'order' key.
Hello,
after last update I got the following error:
ErrorException in Menu.php line 44: Argument 3 passed to Caffeinated\Menus\Menu::__construct() must be an instance of Collective\Html\HtmlBuilder, instance of Illuminate\Html\HtmlBuilder given, called in E:\Entwicklung\htdocs\netconcept-cms\vendor\caffeinated\menus\src\Caffeinated\Menus\MenusServiceProvider.php on line 47 and defined
The hole day was all okay.
in Menu.php line 44
at HandleExceptions->handleError('4096', 'Argument 3 passed to Caffeinated\Menus\Menu::__construct() must be an instance of Collective\Html\HtmlBuilder, instance of Illuminate\Html\HtmlBuilder given, called in E:\Entwicklung\htdocs\netconcept-cms\vendor\caffeinated\menus\src\Caffeinated\Menus\MenusServiceProvider.php on line 47 and defined', 'E:\Entwicklung\htdocs\netconcept-cms\vendor\caffeinated\menus\src\Caffeinated\Menus\Menu.php', '44', array('config' => object(Repository), 'view' => object(Factory))) in Menu.php line 44
at Menu->__construct(object(Repository), object(Factory), object(HtmlBuilder), object(UrlGenerator)) in MenusServiceProvider.php line 47
at MenusServiceProvider->Caffeinated\Menus\{closure}(object(Application)) in Container.php line 290
at Container->Illuminate\Container\{closure}(object(Application), array()) in Container.php line 773
at Container->build(object(Closure), array()) in Container.php line 656
at Container->make('menu', array()) in Application.php line 644
at Application->make('menu') in Container.php line 1231
at Container->offsetGet('menu') in Facade.php line 148
at Facade::resolveFacadeInstance('menu') in Facade.php line 118
at Facade::getFacadeRoot() in Facade.php line 202
at Facade::__callStatic('make', array('backend', object(Closure))) in menu.php line 13
at Menu::make('backend', object(Closure)) in menu.php line 13
at include('E:\Entwicklung\htdocs\netconcept-cms\modules\Core\Http\menu.php') in Module.php line 223
at Module->registerFiles() in Module.php line 171
at Module->register() in Repository.php line 301
at Repository->register() in BootstrapServiceProvider.php line 14
at BootstrapServiceProvider->boot()
at call_user_func_array(array(object(BootstrapServiceProvider), 'boot'), array()) in Container.php line 523
at Container->call(array(object(BootstrapServiceProvider), 'boot')) in Application.php line 703
at Application->bootProvider(object(BootstrapServiceProvider)) in Application.php line 685
at Application->Illuminate\Foundation\{closure}(object(BootstrapServiceProvider), '23')
at array_walk(array(object(EventServiceProvider), object(RoutingServiceProvider), object(AuthServiceProvider), object(ControllerServiceProvider), object(CookieServiceProvider), object(DatabaseServiceProvider), object(EncryptionServiceProvider), object(FilesystemServiceProvider), object(FormRequestServiceProvider), object(FoundationServiceProvider), object(PaginationServiceProvider), object(SessionServiceProvider), object(ValidationServiceProvider), object(ViewServiceProvider), object(AppServiceProvider), object(BusServiceProvider), object(ConfigServiceProvider), object(EventServiceProvider), object(RouteServiceProvider), object(ServiceProvider), object(ConsoleServiceProvider), object(ContractsServiceProvider), object(ModulesServiceProvider), object(BootstrapServiceProvider), object(EntrustServiceProvider), object(ServiceProvider), object(BusServiceProvider), object(MailServiceProvider), object(QueueServiceProvider), object(CoreServiceProvider), object(TranslationServiceProvider), object(HtmlServiceProvider), object(MenusServiceProvider), object(HtmlServiceProvider)), object(Closure)) in Application.php line 686
at Application->boot() in BootProviders.php line 15
at BootProviders->bootstrap(object(Application)) in Application.php line 181
at Application->bootstrapWith(array('Illuminate\Foundation\Bootstrap\DetectEnvironment', 'Illuminate\Foundation\Bootstrap\LoadConfiguration', 'Illuminate\Foundation\Bootstrap\ConfigureLogging', 'Illuminate\Foundation\Bootstrap\HandleExceptions', 'Illuminate\Foundation\Bootstrap\RegisterFacades', 'Illuminate\Foundation\Bootstrap\RegisterProviders', 'Illuminate\Foundation\Bootstrap\BootProviders')) in Kernel.php line 199
at Kernel->bootstrap() in Kernel.php line 110
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 84
at Kernel->handle(object(Request)) in index.php line 53
I appreciate that you suggest a home for the menu-specific code in ones app. However, I'm still a bit perplexed.
Your wiki's quick-start section states that it's best, by convention, to place the code in a service provider. That is all well and good... Until you want to use the filter-method to filter out menu-items based on e.g. the role of the logged in user. Session data is unavailable from a provider, so you can't really do that without a workaround of some sort. At least this was the case, last time I looked into it.
The "Basics of Menus"-section contradicts the quick-start section by stating that the ideal place for the menu-code is a middleware. I find that a middleware is more appropriate, but still not without some minor problems. For instance, if you define the menu-middleware as global and your app has some pages without the menu, like a login-page, your package will still attempt to build the menu. Basically, the route decides if the menu is created or not.
A third option, not mentioned in the docs, is a dedicated view composer. First, you need a provider to bind views and composers together. This means you get to decide, in a clean way, when a given view composer should be used. In the composer itself, you also have access to the currently logged in user, which is nice. More importantly, the view is the deciding factor for whether the menu is created or not, giving you much more granular control than the middleware approach.
How about a dedicated section in your wiki that talks about the alternatives? Laravel itself is all about the freedom to choose for oneself, after all :-)
Edit: Wording and typos.
I got this error when trying to setup menus.
Undefined variable: menu_example
I followed all the instructions, am I missing something?
Hi,
Do you have any idea why in filter closure, dd(Auth::user()) returns null? I'm already logged in.
Thanks, and sorry for this rookie question!
This is a question or a request it depends.
There is some way to change the id property of the menu item?
It's not to add a property called id with $menu->add('xxx', 'xxx')->attribute('id', 1) what i'm asking. It's like having a method to change the id like
$menu->add('xxx', '#');
$menu->xxx->setId(1);
It will be a good addition to a database menu because it's easier to declare parents and childs.
There is documentation for adding attributes to menu items, but how about the menu parent element?
I tried doing a $menu->attribute, but that did not work.
I would like to add class names to the
$menu->add('Categories',
array(
'class' => '',
'id' => 'showLeft'
))
->link->href('#');
The above won't show class or id in the html link.
I'm not sure if this is a bug or feature request.
Are you planning to add in the divider functionality?
Hi, I tried to install the package and got the following error:
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for caffeinated/menus ~1.0 -> satisfiable by caffeinated/menus[v1.0.7].
- caffeinated/menus v1.0.7 requires laravelcollective/html 5.0.* -> no matching package found.
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting
see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.
Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.
My composer contain
"laravelcollective/html": "5.1.*",
I tried a downgrade but contains many more errors. It is possible to make it compatible with laravel 5.1?
Hey,
I build the menu from several places and using Menu::get for add items to my menu.
But when I do that I can't sort the menu.
How should I sort the menu anyway?
Thanks
Here"s part of the menu I'm building.
$menu->add('HR', 'school');
$menu->school->add('Employees', 'employees');
This will error out with
Call to a member function add() on a non-object
However this works
$menu->add('School', 'school');
$menu->school->add('Employees', 'employees');
I could figure out why this was Happening until I realized that the Route and Link name have to be the same.
Is this a bug?
Hi
Please take a look at the attached image.
Using the asUl()
method it seems that an empty tag attribute (both attribute name and value) is being injected into each li
element.
I haven't looked at the code, but I expect that this can be solved by simply inserting an if-empty statement when looping over any additionally set attributes.
I'm currently trying to have the builder check if each item will give access before it's added to the tree.
(ACL-based, defined on the routes)
Basically what I'm trying to do, is filter out items that are not accessible to the user.
(If a root item is not allowed via ACL, then all underlying items are also prohibited)
Initially I was looking into overriding Builder::add() to match the given URL to the routes, and then checking the route if it matches for access. But If an item is not allowed, I'm not able to return nothing from add().
Am I looking into the wrong direction? ;-)
Call to undefined method "getcontrollerAction" in Builder.php line 180
I have no idea if I've done this correctly. Basically, I did as you suggested: Made a new service provider called MenuServiceProvider with two methods - one empty register-method and a boot-method that has the code from the example in your readme (\Menu::make(...)). I then registered it in config/app.php.
Now I just get this:
ReflectionException in Container.php line 776:
Class html does not exist
nice work man.
gave it a try and it is conflicting with illuminate/html
Hi,
within #32 you build in a method to get current active state via
$item->data('active')
But when I have a route to edit or create (example users/create) this active state is not set. But main route "users" is active.
Can u fix this ?
Since we still can use the official package, can we have some sort of option to switch which HTML package to be use in our app? Right now, I have to change all the HTML package to Collective version if I want to use this package.
Thank you very much, you made a great job and saved a lot of my time!
Just little correction for wiki in bootstrap template: we need to use {!! $item->title !!}
to disable auto-escaping and now we can use icons.
So, the new template is:
@foreach($items as $item)
<li @if($item->hasChildren())class ="dropdown"@endif>
@if($item->link) <a @if($item->hasChildren()) class="dropdown-toggle" data-toggle="dropdown" @endif href="{{ $item->url() }}">
{!! $item->title !!}
@if($item->hasChildren()) <b class="caret"></b> @endif
</a>
@else
{!! $item->title !!}
@endif
@if($item->hasChildren())
<ul class="dropdown-menu">
@foreach($item->children() as $child)
<li><a href="{{ $child->url() }}">{!! $child->title !!}</a></li>
@endforeach
</ul>
@endif
</li>
@if($item->divider)
<li{{\HTML::attributes($item->divider)}}></li>
@endif
@endforeach
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.