Looking to hire Laravel developers? Try LaraJobs

laravel-json-menu maintained by atthakasem

Description
A simple Laravel menu builder using JSON
Last update
2021/12/08 17:55 (dev-main)
License
Downloads
127

Comments
comments powered by Disqus

Laravel Json Menu

Latest Version on Packagist Total Downloads

This package is currently under development. Use at your own risk!

Installation

Via Composer

$ composer require atthakasem/laravel-json-menu

Usage

  1. Create a menu file in resouces/menus/main.json containing an array of pages. A page can be represented by a string or an object.

    [
        "News",
        "About us",
        {
            "name": "Home",
            "url": "/"
        },
        {
            "name": "Career",
            "children": ["Our perks", "Vacancies"]
        },
        {
            "name": "Our partner",
            "url": "https://www.google.com",
            "external": true
        },
        "Contact us",
        {
            "name": "Data protection",
            "class": "my-css-class another-one"
        }
    ]
    
  2. Use the menu in your blade file via @menu() or @menu('main'). The resulting output will be:

    <ul>
        <li><a href="http://localhost/news">News</a></li>
        <li><a href="http://localhost/about-us">About us</a></li>
        <li><a href="http://localhost" class="active">Home</a></li>
        <li>
            <a href="http://localhost/career">Career</a>
            <ul>
                <li><a href="http://localhost/career/our-perks">Our perks</a></li>
                <li><a href="http://localhost/career/vacancies">Vacancies</a></li>
            </ul>
        </li>
        <li><a href="https://www.google.com" target="_blank">Our partner</a></li>
        <li><a href="http://localhost/contact-us">Contact us</a></li>
        <li><a href="http://localhost/data-protection" class="my-css-class another-one">Data protection</a></li>
    </ul>
    

Options

These JSON properties can be used. When using object notation, only "name" is mandatory.

Property Description Value type Default
name Displayed name of the menu item string N/A
url Relative URL to desired page string Illuminate\Support\Str::slug($name)
route Named route to desired page string null
external Open link in a new tab boolean false
children Subpages of the menu item array []
class CSS classes of the menu item string null

Changing the path to the JSON menu files

$ php artisan vendor:publish --provider="Atthakasem\LaravelJsonMenu\LaravelJsonMenuServiceProvider"

will create a config file config/laravel-json-menu.php where you can change the path.

Change log

Please see the changelog for more information on what has changed recently.

Contributing

Please see contributing.md for details and a todolist.

Security

If you discover any security related issues, please email author email instead of using the issue tracker.

Credits

License

Please see the license file for more information.