Coder Social home page Coder Social logo

laravel-menus's Introduction

Laravel Menus

Latest Version on Packagist Software License Build Status Scrutinizer Coverage SensioLabsInsight Quality Score Total Downloads

Laravel laravel-menus
5.4 ^0.5
5.5 ^1.0
5.6 ^2.0
5.7 ^3.0
5.8 ^4.0
6.0 ^5.0
8.0 ^7.0

nwidart/laravel-menus is a laravel package which created to manage menus. It has a feature called presenters which enables easy styling and custom structure of menu rendering.

This package is a re-published, re-organised and maintained version of pingpong/menus, which isn't maintained anymore. This package is used in AsgardCMS.

With one big added bonus that the original package didn't have: tests.

Documentation

You'll find installation instructions and full documentation on https://nwidart.com/laravel-menus/.

Credits

License

The MIT License (MIT). Please see License File for more information.

laravel-menus's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-menus's Issues

Sidebar for current page

Hi @nWidart ,

I am working on theme sidebar, but I am unable to get the menu in sidebar.
Let's see an example:
I have main Menu with 5 parents links and each have children items, now if I visit a page which is in parent no.2, thus I want to display only that parent in sidebar based on current page details, you can see it here what I mean it in screenshot?
main menu in sidebar issue

Could you please guide me how's that possible?

Make top of submenu a link

Hi. Is there a way to make the top of the submenu a link as well? I don't see any parameters to make the top of the menu a link in that in $Iterm->dropdown(). Is there a way to add it after the submenu has been created? I need to be able to make that a link as well, but I don't see that as an option.

For example, here, "About" is not clickable and I don't see a way to make it a link to another page:

		$menu->dropdown('About', function ($sub) {

			$sub->add([
				'route' => ['things', []],
				'title' => 'Things',
				'attributes' => [
					'name' => 'things'
				]
			]);

			$sub->add([
				'route' => ['contact', []],
				'title' => 'Contact Us',
				'attributes' => [
					'name' => 'contact'
				]
			]);

		},);

Laravel 9 installation issue

composer require nwidart/laravel-menus -W
Using version ^7.0 for nwidart/laravel-menus
./composer.json has been updated
Running composer update nwidart/laravel-menus --with-all-dependencies
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

Problem 1
- Root composer.json requires nwidart/laravel-menus ^7.0 -> satisfiable by nwidart/laravel-menus[7.0].
- nwidart/laravel-menus 7.0 requires laravelcollective/html 6.2.* -> found laravelcollective/html[v6.2.0, v6.2.1] but it conflicts with your root composer.json require (^6.3).

Installation failed, reverting ./composer.json and ./composer.lock to their original content.

It can be solved changing the lines

"require": {
"php": ">=7.3",
"illuminate/support": "^8.0",
"illuminate/config": "^8.0",
"illuminate/view": "^8.0",
"laravelcollective/html": "6.2.*"
},

to

"require": {
"php": ">=7.3",
"illuminate/support": ">=8.0",
"illuminate/config": ">=8.0",
"illuminate/view": ">=8.0",
"laravelcollective/html": ">=6"
},

No problems on my needs, but futher tests should be passed

Support Laravel 7 ?

When you think this package will be update for Lavarel 7 ?
Thanks for your help

$menuitem->hideWhen : determining whether menu item is hidden should be based on customized global or menu specific logic

I'm searching for a practical way to use the $menuitem->hideWhen property

  1. Each menu item to be shown or hidden does not appear to be passed to the hideWhen function in order for the function to determine whether the menu item should be displayed, making it less useful.
  2. The logic for whether a menuitem is seen or not seen is probably -not- going to be different for each menu item. More than likely, it will be the same for all menus on the site, or at the maximum different for each menu. Having to set one property per menu item seems impractical.

There should be some way of having a global or maybe menu specific function to hide or show menu items. I could then, for example, base it on route permissions.

This would also be a more simple way to solve the problem of a developer wanting to show/hide menus based on spatie/laravel-permissions, mentioned here: #58

I'll see what I can do to change this. Or, I might be missing something. Please let me know or post a link to a good example.

Remove dependency to laravelcollective/html

This is only used in MenuItem->getAttributes

Seems overkill to pull that dependency just for that.

On top of that, that function of MenuItem does not really belong to that class, that should be the presenter's job to convert an array of attributes into a string.

Class 'Menu' not found

Class 'Menu' not found in {dir}\config\support\menus.php.
In the file {dir}\config\support\menus.php, I added the following code:

return \Menu::create('sidebar', function ($menu) {
    $menu->setPresenter(NavbarPresenter::class);

    $menu->header('MAIN NAVIGATION');


    $menu->url('home', 'Home', ['target' => 'blank'], ['icon' => 'fa fa-circle-o']);

    $menu->add([
        'route' => [
            'backend.dashboard',
            ['user' => 'nwidart']
        ],
        'title' => 'Visit My Profile',
        'icon'=>'fa fa-circle-o',
        'attributes' => [
            'target' => '_blank'
        ],
    ]);

    $menu->dropdown('Settings', function ($sub) {
        $sub->url('settings/account', 'Account', ['icon' => 'fa fa-circle-o']);
        $sub->url('settings/password', 'Password', ['icon' => 'fa fa-circle-o']);
        $sub->url('settings/design', 'Design', ['icon' => 'fa fa-circle-o']);
    }, ['icon' => 'fa fa-circle-o']);

});

In the file config.app, i added:

'providers' => [
        Nwidart\Menus\MenusServiceProvider::class,
],

 'aliases' => [
        'Menu' => Nwidart\Menus\Facades\Menu::class,
]

but when i run, i received error:
Class 'Menu' not found in {dir}\config\support\menus.php

I tried adding the config\support\menus.php file to the composer.json file:
"autoload": { "files": ["config/support/menus.php"] }

I still received error
Class 'Menu' not found in {dir}\config\support\menus.php

Subclassing as a way to distinguish between menu items

Instead of stuffing lots of things into a single MenuItem class, we should instead let that class focus on storing properties common to each menu item, then have subclasses for each type of menu item.

For example, a DividerItem, HeaderItem, LinkItem, DropdownItem

This would then make it easy for presenters to support rendering for each type of subclass and even could be used to support user-defined menu item classes.

session problem in NWIDART package with laravel8

hey guys please can i have some help,
I try to use session with parameter "session('locales')" in my<menus.php> using nwidart /menus package in laravel8 but this parameter '$locale' return NULL , but i can get it in all other files .
my code in menus.php :

Capture

bug in dropdown()

There appears to be a bug in dropdown(). If only $order, but not $attributes is passed in, the index 2 is incorrect for attributes and $attributes will end up having the integer value for $order. Perhaps check $order to make sure it's an array if people leave $order out of the arguments? Will fix and create pull request as soon as I can figure out how to set up my SSH keys. Let me know if I am incorrect.

   public function dropdown($title, \Closure $callback, $order = null, array $attributes = array())
    {
        $properties = compact('title', 'order', 'attributes');

        if (func_num_args() == 3) {
            $arguments = func_get_args();

            $title = Arr::get($arguments, 0);

            // If only $order is passed in without attributes, 2 is the wrong index
            $attributes = Arr::get($arguments, 2);

            $properties = compact('title', 'attributes');
        }

        $item = MenuItem::make($properties);

        call_user_func($callback, $item);

        $this->items[] = $item;

        return $item;
    }

Installation failed, does anyone has solution on this?

Installation failed, does anyone has solution on this?
Thanks in advance if you have solution.

Your requirements could not be resolved to an installable set of packages.

Problem 1
- Conclusion: remove laravel/framework v7.28.4
- Conclusion: don't install laravel/framework v7.28.4
- nwidart/laravel-menus 4.0.0 requires illuminate/view 5.8.* -> satisfiable by laravel/framework[5.8.x-dev], illuminate/view[5.8.x-dev, v5.8.0, v5.8.11, v5.8.12, v5.8.14, v5.8.15, v5.8.17, v5.8.18, v5.8.19, v5.8.2, v5.8.20, v5.8.22, v5.8.24, v5.8.27, v5.8.28, v5.8.29, v5.8.3, v5.8.30, v5.8.31, v5.8.32, v5.8.33, v5.8.34, v5.8.35, v5.8.36, v5.8.4, v5.8.8, v5.8.9].
- nwidart/laravel-menus 4.0.x-dev requires illuminate/view 5.8.* -> satisfiable by laravel/framework[5.8.x-dev], illuminate/view[5.8.x-dev, v5.8.0, v5.8.11, v5.8.12, v5.8.14, v5.8.15, v5.8.17, v5.8.18, v5.8.19, v5.8.2, v5.8.20, v5.8.22, v5.8.24, v5.8.27, v5.8.28, v5.8.29, v5.8.3, v5.8.30, v5.8.31, v5.8.32, v5.8.33, v5.8.34, v5.8.35, v5.8.36, v5.8.4, v5.8.8, v5.8.9].
- Can only install one of: laravel/framework[5.8.x-dev, v7.28.4].
- don't install illuminate/view 5.8.x-dev|don't install laravel/framework v7.28.4
- don't install illuminate/view v5.8.0|don't install laravel/framework v7.28.4
- don't install illuminate/view v5.8.11|don't install laravel/framework v7.28.4
- don't install illuminate/view v5.8.12|don't install laravel/framework v7.28.4
- don't install illuminate/view v5.8.14|don't install laravel/framework v7.28.4
- don't install illuminate/view v5.8.15|don't install laravel/framework v7.28.4
- don't install illuminate/view v5.8.17|don't install laravel/framework v7.28.4
- don't install illuminate/view v5.8.18|don't install laravel/framework v7.28.4
- don't install illuminate/view v5.8.19|don't install laravel/framework v7.28.4
- don't install illuminate/view v5.8.2|don't install laravel/framework v7.28.4
- don't install illuminate/view v5.8.20|don't install laravel/framework v7.28.4
- don't install illuminate/view v5.8.22|don't install laravel/framework v7.28.4
- don't install illuminate/view v5.8.24|don't install laravel/framework v7.28.4
- don't install illuminate/view v5.8.27|don't install laravel/framework v7.28.4
- don't install illuminate/view v5.8.28|don't install laravel/framework v7.28.4
- don't install illuminate/view v5.8.29|don't install laravel/framework v7.28.4
- don't install illuminate/view v5.8.3|don't install laravel/framework v7.28.4
- don't install illuminate/view v5.8.30|don't install laravel/framework v7.28.4
- don't install illuminate/view v5.8.31|don't install laravel/framework v7.28.4
- don't install illuminate/view v5.8.32|don't install laravel/framework v7.28.4
- don't install illuminate/view v5.8.33|don't install laravel/framework v7.28.4
- don't install illuminate/view v5.8.34|don't install laravel/framework v7.28.4
- don't install illuminate/view v5.8.35|don't install laravel/framework v7.28.4
- don't install illuminate/view v5.8.36|don't install laravel/framework v7.28.4
- don't install illuminate/view v5.8.4|don't install laravel/framework v7.28.4
- don't install illuminate/view v5.8.8|don't install laravel/framework v7.28.4
- don't install illuminate/view v5.8.9|don't install laravel/framework v7.28.4
- Installation request for laravel/framework (locked at v7.28.4, required as ^7.24) -> satisfiable by laravel/framework[v7.28.4].
- Installation request for nwidart/laravel-menus ^4.0 -> satisfiable by nwidart/laravel-menus[4.0.0, 4.0.x-dev].

Installation failed, reverting ./composer.json to its original content.

Use Spatie/html instead of laravelcollective/html

This would help make the code of presenters much cleaner. For instance, an existing method:

    return '<li' . $this->getActiveState($item) . '>
		<a href="' . $item->getUrl() . '" ' . $item->getAttributes() . ' class="nav-link">'
        . $item->title . '</a></li>' . PHP_EOL;

Note that above code is using some rendering functionnality placed in the MenuItem class (which should not be there, see #19)

Using Spatie/html, we can rewrite this as

    $link = html()->a($item->getUrl())
        ->addClass('nav-link')
        ->attributes($item->attributes)
        ->html($item->title);

    return html()->element('li')
        ->addClass('nav-item')
        ->addClassIf($item->isActive(), 'active')
        ->addChild($link);

My Code Doesn't Work !

Menu::create('navbar', function($menu) { // URL, Title, Attributes foreach (Menus::tree() as $item) { $menu->url('/'.$item->name, $item->name, ['target' => 'blank','class' => 'deneem']); foreach ($item['children'] as $child) { echo "<ol>D" . $child->name . "</ol>"; $menu->dropdown('Settings', function ($sub) { $sub->url('settings/account', $child->name); $sub->url('settings/password', 'Password'); $sub->url('settings/design', 'Design'); }); } } });

in dropdown menu i cant access $child varible why ?

Menu not showing the translated title

Hi @nWidart, I am working on creating menus, everything worked well, but when I run the following code in view:
{!! Menu::instance('Main Menu')->getName() !!}
which output the menu name.

Is it possible to have the title of menu instead?
Because in that case we can get the title for different locale.

See that in screenshot below:
main menu title issue

Thank you!

Testing in Laravel 5.5-dev

Hi,

I suppose is a silly question, but how can I test the package in Laravel 5.5-dev.

I try
"nwidart/laravel-menus": "dev-master"
or
"nwidart/laravel-menus": "@dev"

But always says me:

`
Your requirements could not be resolved to an installable set of packages.

Problem 1
- Installation request for nwidart/laravel-menus dev-master -> satisfiable by nwidart/laravel-menus[dev-master].
- Conclusion: remove laravel/framework 5.5.x-dev
- nwidart/laravel-menus dev-master requires illuminate/view 5.4.* -> satisfiable by illuminate/view[5.4.x-dev, v5.4.0, v5.4.13, v5.4.17, v5.4.19, v5.4.27, v5.4.9].
- don't install illuminate/view 5.4.x-dev|don't install laravel/framework 5.5.x-dev
- don't install illuminate/view v5.4.0|don't install laravel/framework 5.5.x-dev
- don't install illuminate/view v5.4.13|don't install laravel/framework 5.5.x-dev
- don't install illuminate/view v5.4.17|don't install laravel/framework 5.5.x-dev
- don't install illuminate/view v5.4.19|don't install laravel/framework 5.5.x-dev
- don't install illuminate/view v5.4.27|don't install laravel/framework 5.5.x-dev
- don't install illuminate/view v5.4.9|don't install laravel/framework 5.5.x-dev
- Installation request for laravel/framework 5.5.* -> satisfiable by laravel/framework[5.5.x-dev].

`
Thanks and best regards

v1 working correctly?

Hi,

I'm trying to implement the v1 in Laravel 5.5 and BootStrap 4.0.

Following the instructions I publish the views to /resources/views/vendor/nwidart/menus with

php artisan vendor:publish --provider="Nwidart\Menus\MenusServiceProvider"

Them I make some changes in the views and use it as follows

    Menu::create($menuName, function ($menu) {           
         $menu->setView('menus::default');
          $menu->url('/', 'Home', []);
          $menu->route('contactus', 'Contacto', [], []);
      });

I modified the file /resources/views/vendor/nwidart/menus/default.blade.php with

<ul class="navbar-nav ml-auto">
  @include('menus::menu')
</ul>

But nothing changes. So I decide to do it with presenters and created a /App/Presenters/FrontMenuNavbarPresenter

and modifid the /config/menus.php file with

return [

    'styles' => [
        //'navbar' => \Nwidart\Menus\Presenters\Bootstrap\NavbarPresenter::class,
        'navbar' => \App\Presenters\FrontMenuNavbarPresenter::class,
       ....
    ],

    'ordering' => false,

];

Obviously I created the FrontMenuNavbarPresenter.php with somithing like


    /**
     * {@inheritdoc }.
     */
    public function getOpenTagWrapper()
    {
        return PHP_EOL . '<ul class="navbar-nav ml-auto">' . PHP_EOL;
    }

And nothing appears in the HTML.

Finally I decide to add the presenter in code like


    Menu::create($menuName, function ($menu) {           
           $menu->setPresenter(\App\Presenters\FrontMenuNavbarPresenter::class);
            $menu->url('/', 'Home', []);
            $menu->route('contactus', 'Contacto', [], []);
        });

And It works well.

What I doing wrong in the views and in config solution or is an issue?

Thanks and best regards

Change Interface

Change method PresenterInterface
public function getChildMenuItems(MenuItem $item);

I have new class MenuItem with new type items but extends Presenter get error compatible class

Custom Icon Wrapper

How do i overwrite the default icon wapper? I want to add some class to the icon before adding font-awesome

Spelling of method

Method hasChilds is improperly named. It should be named hasChildren.

laravel 5.6 compatible?

hi, im trying to install this package in laravel 5.6 but i get this error:

composer require nwidart/laravel-menus

Using version ^1.0 for nwidart/laravel-menus
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

Problem 1
- Conclusion: remove laravel/framework v5.6.29
- Conclusion: don't install laravel/framework v5.6.29
- nwidart/laravel-menus 1.0.0 requires illuminate/view 5.5.* -> satisfiable by illuminate/view[5.5.x-dev, v5.5.0, v5.5.16, v5.5.17, v5.5.2, v5.5.28, v5.5.33, v5.5.34, v5.5.35, v5.5.36, v5.5.37, v5.5.39, v5.5.40].
- nwidart/laravel-menus 1.0.x-dev requires illuminate/view 5.5.* -> satisfiable by illuminate/view[5.5.x-dev, v5.5.0, v5.5.16, v5.5.17, v5.5.2, v5.5.28, v5.5.33, v5.5.34, v5.5.35, v5.5.36, v5.5.37, v5.5.39, v5.5.40].
- don't install illuminate/view 5.5.x-dev|don't install laravel/framework v5.6.29
- don't install illuminate/view v5.5.0|don't install laravel/framework v5.6.29
- don't install illuminate/view v5.5.16|don't install laravel/framework v5.6.29
- don't install illuminate/view v5.5.17|don't install laravel/framework v5.6.29
- don't install illuminate/view v5.5.2|don't install laravel/framework v5.6.29
- don't install illuminate/view v5.5.28|don't install laravel/framework v5.6.29
- don't install illuminate/view v5.5.33|don't install laravel/framework v5.6.29
- don't install illuminate/view v5.5.34|don't install laravel/framework v5.6.29
- don't install illuminate/view v5.5.35|don't install laravel/framework v5.6.29
- don't install illuminate/view v5.5.36|don't install laravel/framework v5.6.29
- don't install illuminate/view v5.5.37|don't install laravel/framework v5.6.29
- don't install illuminate/view v5.5.39|don't install laravel/framework v5.6.29
- don't install illuminate/view v5.5.40|don't install laravel/framework v5.6.29
- Installation request for laravel/framework (locked at v5.6.29, required as 5.6.*) -> satisfiable by laravel/framework[v5.6.29].
- Installation request for nwidart/laravel-menus ^1.0 -> satisfiable by nwidart/laravel-menus[1.0.0, 1.0.x-dev].

Ideas of supporting 5.8?

I know where is another ticket about 5.8 support however this seemed rather empty which is why I'm opening a new ticket.

I was wondering, as the title says, are there plans on supporting Laravel 5.8?

Bootstrap 4

Hi,
https://blackrockdigital.github.io/startbootstrap-modern-business/
As you can see in the Bootstrap 4 menu, the first lavel of link has the class "nav-link". For example

<a class="nav-link" href="about.html">About</a>
In the second level the class is different, For example.
<a class="dropdown-item" href="portfolio-3-col.html">3 Column Portfolio</a>

As I see in the presenter there is only one place to set de class

    public function getMenuWithoutDropdownWrapper($item)
    {
        return '<li class="nav-item" ' . $this->getActiveState($item) . '><a class="nav-link" href="' . $item->getUrl() . '" ' . $item->getAttributes() . '>' . $item->getIcon() . ' ' . $item->title . '</a></li>' . PHP_EOL;
    }

How can we set the correct class in function of depth?

Thanks and best regards

support for Laravel 5.6

$ php artisan --version
Laravel Framework 5.6.3

$ composer require nwidart/laravel-menus
Using version ^1.0 for nwidart/laravel-menus
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for nwidart/laravel-menus ^1.0 -> satisfiable by nwidart/laravel-menus[1.0.0].
    - Conclusion: remove laravel/framework v5.6.3
    - Conclusion: don't install laravel/framework v5.6.3
    - nwidart/laravel-menus 1.0.0 requires illuminate/view 5.5.* -> satisfiable by illuminate/view[5.5.x-dev, v5.5.0, v5.5.16, v5.5.17, v5.5.2, v5.5.28, v5.5.33, v5.5.34].
    - don't install illuminate/view 5.5.x-dev|don't install laravel/framework v5.6.3
    - don't install illuminate/view v5.5.0|don't install laravel/framework v5.6.3
    - don't install illuminate/view v5.5.16|don't install laravel/framework v5.6.3
    - don't install illuminate/view v5.5.17|don't install laravel/framework v5.6.3
    - don't install illuminate/view v5.5.2|don't install laravel/framework v5.6.3
    - don't install illuminate/view v5.5.28|don't install laravel/framework v5.6.3
    - don't install illuminate/view v5.5.33|don't install laravel/framework v5.6.3
    - don't install illuminate/view v5.5.34|don't install laravel/framework v5.6.3
    - Installation request for laravel/framework (locked at v5.6.3, required as 5.6.*) -> satisfiable by laravel/framework[v5.6.3].


Installation failed, reverting ./composer.json to its original content.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.