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

App Business Menu Bundle Laravel Package

alphalemon/app-business-menu-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require alphalemon/app-business-menu-bundle
    

    Ensure alphalemon/alphalemon-cms-bundle is installed (dev dependency) and properly configured in your Laravel project.

  2. Publish Assets & Config

    php artisan vendor:publish --provider="AlphaLemon\BusinessMenuBundle\BusinessMenuBundle" --tag=config
    php artisan vendor:publish --provider="AlphaLemon\BusinessMenuBundle\BusinessMenuBundle" --tag=public
    

    This registers the menu content type and editor in the CMS.

  3. First Use Case: Create a Menu

    • Navigate to the AlphaLemon CMS dashboardContent Types → Locate "Business Menu".
    • Create a new menu entry via the editor UI (drag-and-drop or manual input).
    • Assign it to a page template or layout in your theme.
  4. Render in Blade

    @inject('businessMenu', 'AlphaLemon\BusinessMenuBundle\Service\BusinessMenuService')
    {{ $businessMenu->render('menu-slug-or-id') }}
    

    Replace 'menu-slug-or-id' with your menu’s identifier (defined in the CMS).


Implementation Patterns

Core Workflows

  1. Menu Creation & Management

    • Use the CMS editor to define hierarchical menus (nested items, icons, URLs, or content blocks).
    • Leverage menu types (e.g., primary, footer, mega-menu) via the menu_type field in the CMS.
  2. Dynamic Rendering

    • Service-Based Rendering:
      $menuItems = $businessMenu->getMenuItems('header-menu');
      foreach ($menuItems as $item) {
          echo '<li><a href="' . $item->url . '">' . $item->title . '</a></li>';
      }
      
    • Blade Directives (if supported):
      @businessMenu('footer-menu', 'partials.menu-item')
      
  3. Integration with Routes

    • Fetch menu items and dynamically generate route names:
      $menu = $businessMenu->findBySlug('main-nav');
      $routeName = $menu->items->first()->route_name;
      url($routeName);
      
  4. Theming & Styling

    • Override default templates by publishing views:
      php artisan vendor:publish --tag=business-menu-views
      
    • Extend CSS/JS via the public publish tag.
  5. Conditional Menus

    • Use menu visibility rules (e.g., user roles, locale) in the CMS editor.
    • Filter menus in code:
      $activeMenu = $businessMenu->getActiveMenu(request()->path());
      

Advanced Patterns

  • Menu Caching:
    Cache::remember('menu-header', now()->addHours(1), function () {
        return $businessMenu->getMenu('header');
    });
    
  • Event Listeners: Listen for menu updates to invalidate caches or sync with external systems:
    BusinessMenuBundle::onMenuUpdated(function ($menu) {
        // Sync with a headless CMS or analytics tool
    });
    
  • API Endpoints: Expose menu data via Laravel routes:
    Route::get('/api/menus/{slug}', [BusinessMenuController::class, 'show']);
    

Gotchas and Tips

Pitfalls

  1. Missing CMS Integration

    • Issue: The bundle requires alphalemon-cms-bundle (dev dependency). If not installed, the editor and content type won’t register.
    • Fix: Ensure alphalemon-cms-bundle is installed and configured before using this bundle.
  2. Menu Slug Collisions

    • Issue: Duplicate menu slugs can break rendering or cause silent failures.
    • Fix: Validate slugs in the CMS editor or add a unique constraint in migrations.
  3. Template Overrides Not Loading

    • Issue: Custom views aren’t picked up after publishing.
    • Fix: Clear Laravel’s view cache:
      php artisan view:clear
      
  4. Performance with Large Menus

    • Issue: Deeply nested menus may slow down rendering.
    • Fix: Implement lazy-loading or pagination for menu items in the frontend.
  5. Deprecated Methods

    • Issue: The bundle is new (1 star, low activity). Check for breaking changes in minor updates.
    • Fix: Review the CHANGELOG.md (if exists) or open an issue on GitHub for clarification.

Debugging Tips

  • Log Menu Data:

    \Log::debug('Menu items:', $businessMenu->getMenuItems('test-menu'));
    
  • Check Published Config:

    php artisan config:clear
    

    Then inspect config/business_menu.php for overrides.

  • Editor Not Showing:

    • Verify the CMS bundle’s apps config includes business_menu.
    • Check browser console for JS errors (e.g., missing dependencies).

Extension Points

  1. Custom Menu Fields

    • Extend the menu model or use the CMS’s field extensions:
      // Example: Add a 'priority' field
      $businessMenu->addField('priority', 'integer', ['default' => 0]);
      
    • Note: May require modifying the bundle’s migrations or entity classes (check src/Entity/MenuItem.php).
  2. Custom Renderers

    • Override the default renderer by binding a new service:
      $this->app->bind('AlphaLemon\BusinessMenuBundle\Renderer\MenuRendererInterface', CustomMenuRenderer::class);
      
  3. Menu Sync with External Sources

    • Use the BusinessMenuBundle::onMenuUpdated event to sync with:
      • A headless CMS (e.g., Strapi, Contentful).
      • A database replica or analytics tool.
  4. Localization

    • If using Laravel Localization, ensure menu items respect the app locale:
      $menu = $businessMenu->getMenu('main-nav', app()->getLocale());
      
  5. Testing

    • Mock the service in tests:
      $this->app->instance('AlphaLemon\BusinessMenuBundle\Service\BusinessMenuService', MockBusinessMenuService::class);
      
    • Test menu rendering in isolation:
      $this->get('/')->assertSee('Menu Item Title');
      
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.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware