Weave 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

Laravel Dynamic Menu Laravel Package

rapidwebltd/laravel-dynamic-menu

Laravel Dynamic Menu lets you build database-driven navigation menus in Laravel without hardcoding links. Define nested menu items, order them, render them in Blade, and automatically highlight the active page for cleaner, more maintainable navigation.

View on GitHub
Deep Wiki
Context7

Getting Started

  1. Install the package via Composer and publish its config and migrations:
    composer require <vendor>/<package>
    php artisan vendor:publish --provider="<Vendor>\<Package>\<PackageServiceProvider>"
    php artisan migrate
    
  2. Look first at the published config file. It controls table prefixes, model bindings, and view paths.
  3. Inspect the core models (Menu, MenuItem / MenuHeading) and the polymorphic target relation. A menu item may link to any Eloquent model or stand alone as a heading.
  4. First use case: create a menu, add a few items, optionally attach a Page or Post as the polymorphic target, set sibling ordering with decimal positions, then render the tree in a Blade partial.

Implementation Patterns

  • Programmatic menu building
    Create menus and items in seeders or admin controllers. Use the package’s fluent API (or model create) to attach items to a parent and assign a decimal position.
  • Polymorphic targets
    Attach any model via morphTo (target_type, target_id). Leave the target empty for headings, separators, or custom links. The v1.1.0 release fixes fresh-install persistence for target-less headings.
  • Sibling ordering
    The package assigns deterministic default positions while allowing explicit decimal positions (e.g. 1.0, 1.5, 2.0). Use decimals to insert between siblings without renumbering the whole set.
  • Configurable table prefix
    Set the prefix in config before running migrations. v1.1.0 corrects both migration rollbacks to drop the actual prefixed tables.
  • Rendering
    Use a recursive Blade partial that eager-loads children and target to avoid N+1 queries. Cache the rendered tree or the underlying menu query, invalidating on model events.
  • Admin integration
    Build a drag-and-drop UI that posts new decimal positions. Use route model binding for targets and validate that the target model exists when a type is provided.

Gotchas and Tips

  • Decimal precision
    Avoid extremely tight gaps (e.g. 1.0001 vs 1.0002). Use a sensible step (0.1 or 0.5) and normalise positions occasionally if the tree grows deep.
  • Fresh installs and target-less headings
    Prior versions could drop headings without polymorphic targets on fresh installs; v1.1.0 fixes this. If upgrading, re-run migrations or verify existing heading rows.
  • Migration rollbacks with prefixes
    Always confirm the prefix config is correct before rolling back. v1.1.0 fixes rollbacks to target prefixed tables, but an incorrect prefix will still leave tables behind.
  • Version compatibility
    The package supports Laravel 5.5–13 and PHP 7.0+. If your app uses newer PHP features, ensure the package’s service provider and config are still loaded correctly. Test on your target Laravel/PHP pair using the included SQLite test suite as a reference.
  • Debugging ordering
    Inspect the position column and the sibling query scope. If items appear out of order, check for duplicate or null positions and verify the default ordering logic.
  • Extension points
    Override models and views via config. Use model observers or events (created, updated, deleted) to clear menu caches. For custom link types, extend the polymorphic target resolution in your own service.
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.
jinas/dhivatar
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource