Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Module Menu Laravel Package

dizatech/module-menu

Laravel package for managing and rendering module-based menus. Includes an admin UI to create menus, Blade components for sidebar/front-end output, migrations, and seeder-based menu definitions for deployable, migratable menu setups across modules.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require dizatech/module-menu
    

    Publish the configuration file:

    php artisan vendor:publish --provider="Dizatech\ModuleMenu\ModuleMenuServiceProvider" --tag="config"
    
  2. Basic Configuration Edit config/module-menu.php to define your modules and their menu items:

    'modules' => [
        'admin' => [
            'label' => 'Admin Panel',
            'icon' => 'fas fa-tachometer-alt',
            'items' => [
                ['label' => 'Dashboard', 'route' => 'admin.dashboard'],
                ['label' => 'Users', 'route' => 'admin.users.index'],
            ],
        ],
    ],
    
  3. First Usage Render the menu in a Blade view:

    @menu('admin')
    

    Or dynamically fetch it in a controller:

    $menu = \Dizatech\ModuleMenu\Facades\ModuleMenu::get('admin');
    

Implementation Patterns

Module-Based Menu Structure

  • Grouping by Module: Organize menus by logical modules (e.g., admin, frontend, settings).

    'modules' => [
        'frontend' => [
            'label' => 'Public Site',
            'items' => [
                ['label' => 'Home', 'route' => 'home'],
                ['label' => 'Blog', 'route' => 'blog.index'],
            ],
        ],
    ],
    
  • Nested Submenus Use the items array recursively for hierarchical menus:

    'admin' => [
        'items' => [
            [
                'label' => 'Content',
                'items' => [
                    ['label' => 'Posts', 'route' => 'admin.posts.index'],
                    ['label' => 'Categories', 'route' => 'admin.categories.index'],
                ],
            ],
        ],
    ],
    

Dynamic Menu Generation

  • Conditional Rendering Use Blade directives to show/hide menus based on user roles or permissions:

    @auth
        @menu('admin', ['showIf' => function () {
            return auth()->user()->isAdmin();
        }])
    @endauth
    
  • Route-Based Active States Highlight active menu items by route:

    'items' => [
        ['label' => 'Dashboard', 'route' => 'admin.dashboard', 'activeWhen' => 'admin.*'],
    ],
    

Integration with Laravel Features

  • Middleware for Module Access Restrict menu visibility via middleware:

    Route::group(['middleware' => 'can:access-admin'], function () {
        // Admin routes
    });
    
  • Localization Support Localize menu labels:

    'items' => [
        ['label' => trans('menu.dashboard'), 'route' => 'admin.dashboard'],
    ],
    

Gotchas and Tips

Common Pitfalls

  • Route Name Mismatches Ensure route values in the config match your actual Laravel route names. Use php artisan route:list to verify.

  • Caching Issues Clear the view cache if menus don’t update after config changes:

    php artisan view:clear
    
  • Nested Item Syntax Incorrect nesting can break rendering. Validate JSON structure:

    // Correct:
    'items' => [['label' => 'Submenu', 'items' => [...]],]
    
    // Incorrect (missing array wrapper):
    'items' => ['label' => 'Submenu', 'items' => [...]]
    

Debugging Tips

  • Dump Menu Structure Log the raw menu data for debugging:

    dd(\Dizatech\ModuleMenu\Facades\ModuleMenu::get('admin'));
    
  • Check Config Loading Verify the config file is published and loaded:

    dd(config('module-menu'));
    

Extension Points

  • Custom Menu Providers Extend functionality by creating a custom provider:

    use Dizatech\ModuleMenu\Contracts\MenuProvider;
    
    class CustomMenuProvider implements MenuProvider {
        public function getMenu($module) {
            // Custom logic
        }
    }
    

    Register it in config/module-menu.php:

    'provider' => \App\Providers\CustomMenuProvider::class,
    
  • Dynamic Menu Items Fetch menu items from a database or API:

    'items' => function () {
        return \App\Models\MenuItem::where('module', 'admin')->get()->toArray();
    },
    
  • Event-Based Updates Trigger menu rebuilds on module changes via events:

    event(new \App\Events\ModuleUpdated($module));
    

    Listen for updates in a service provider:

    \App\Events\ModuleUpdated::class => function () {
        \Dizatech\ModuleMenu\Facades\ModuleMenu::clearCache();
    },
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope