{"id":13805788,"url":"https://github.com/spatie/laravel-navigation","last_synced_at":"2025-05-15T07:05:17.190Z","repository":{"id":37409310,"uuid":"263643110","full_name":"spatie/laravel-navigation","owner":"spatie","description":"Manage menus, breadcrumbs, and other navigational elements in Laravel apps","archived":false,"fork":false,"pushed_at":"2024-09-20T13:16:12.000Z","size":88,"stargazers_count":525,"open_issues_count":0,"forks_count":33,"subscribers_count":13,"default_branch":"main","last_synced_at":"2025-05-14T23:33:56.220Z","etag":null,"topics":["laravel","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spatie.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"spatie","custom":"https://spatie.be/open-source/support-us"}},"created_at":"2020-05-13T13:48:52.000Z","updated_at":"2025-05-10T06:05:15.000Z","dependencies_parsed_at":"2024-03-05T16:50:55.759Z","dependency_job_id":"b16d269b-f9c7-4750-bb6d-a45a35dc7f87","html_url":"https://github.com/spatie/laravel-navigation","commit_stats":{"total_commits":86,"total_committers":23,"mean_commits":3.739130434782609,"dds":0.8023255813953488,"last_synced_commit":"899de266363496c030797e4c61016e3685d11f7d"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-navigation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-navigation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-navigation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-navigation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spatie","download_url":"https://codeload.github.com/spatie/laravel-navigation/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254292040,"owners_count":22046426,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["laravel","php"],"created_at":"2024-08-04T01:01:04.841Z","updated_at":"2025-05-15T07:05:12.181Z","avatar_url":"https://github.com/spatie.png","language":"PHP","funding_links":["https://github.com/sponsors/spatie","https://spatie.be/open-source/support-us"],"categories":["Resources"],"sub_categories":["Server-side"],"readme":"\n[\u003cimg src=\"https://github-ads.s3.eu-central-1.amazonaws.com/support-ukraine.svg?t=1\" /\u003e](https://supportukrainenow.org)\n\n# Manage menus, breadcrumbs, and other navigational elements in Laravel apps\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/laravel-navigation.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-navigation)\n![run-tests](https://github.com/spatie/laravel-navigation/workflows/run-tests/badge.svg)\n[![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-navigation.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-navigation)\n\nLaravel Navigation is meant to be the spiritual successor of [Laravel Menu](https://github.com/spatie/laravel-menu). Laravel Menu will still be actively maintained, but there are a few principal differences between the two packages.\n\nThe main goal of Laravel Menu is to build HTML menus from PHP. Laravel Navigation describes an application's navigation tree, which can be used as a base to create navigational elements like menus and breadcrumbs. Laravel Menu has a rich API for HTML generation. Laravel Navigation doesn't do any HTML generation (although we might ship some Blade files in the future). Instead, Laravel Navigation should give you the flexibility to build your own UI without worrying about the complexity of navigation trees and active state. Think of it as a [renderless component](https://adamwathan.me/renderless-components-in-vuejs/).\n\n```php\nNavigation::make()\n    -\u003eadd('Home', route('home'))\n    -\u003eadd('Blog', route('blog.index'), fn (Section $section) =\u003e $section\n        -\u003eadd('All posts', route('blog.index'))\n        -\u003eadd('Topics', route('blog.topics.index'))\n    )\n    -\u003eaddIf(\n        Auth::user()-\u003eisAdmin(),\n        'Admin',\n        route('admin.index'),\n        fn (Section $section) =\u003e $section-\u003eadd('Create post', route('blog.create'))\n    );\n```\n\nIf you want to register your navigation in a service provider, which is recommended, you can use the [Laravel container events](https://laravel.com/docs/10.x/container#container-events) to add items to the navigation.\n\n```php\nnamespace App\\Providers;\n\nuse Illuminate\\Support\\ServiceProvider;\nuse Spatie\\Navigation\\Navigation;\nuse Spatie\\Navigation\\Section;\n\nclass NavigationServiceProvider extends ServiceProvider\n{\n    public function register(): void\n    {\n        $this-\u003eapp-\u003eresolving(Navigation::class, function (Navigation $navigation): Navigation {\n            return $navigation\n                -\u003eadd('Home', route('home'))\n                -\u003eadd('Blog', route('blog.index'), fn (Section $section) =\u003e $section\n                    -\u003eadd('All posts', route('blog.index'))\n                    -\u003eadd('Topics', route('blog.topics.index'))\n                )\n                -\u003eaddIf(\n                    Auth::user()-\u003eisAdmin(),\n                    'Admin',\n                    route('admin.index'),\n                    fn (Section $section) =\u003e $section-\u003eadd('Create post', route('blog.create'))\n                );\n        });\n    }\n}\n```\n\nA navigation object can be rendered to a tree, or to breadcrumbs.\n\nSome examples when visiting `/blog/topics/laravel`:\n\n```php\n// Render to tree\nNavigation::make()-\u003etree();\n```\n\n```json\n[\n    { \"title\": \"Home\", \"url\": \"/\", \"active\": false, \"attributes\": [], \"children\": [], \"depth\": 0 },\n    {\n        \"title\": \"Blog\",\n        \"url\": \"/blog\",\n        \"active\": false,\n        \"attributes\": [],\n        \"children\": [\n            { \"title\": \"All posts\", \"url\": \"/blog\", \"active\": false, \"attributes\": [], \"children\": [], \"depth\": 1 },\n            { \"title\": \"Topics\", \"url\": \"/blog/topics\", \"active\": true, \"attributes\": [], \"children\": [], \"depth\": 1 }\n        ],\n        \"depth\": 0\n    },\n    {\n        \"title\": \"Admin\",\n        \"url\": \"/admin\",\n        \"active\": false,\n        \"attributes\": [],\n        \"children\": [\n            { \"title\": \"Create post\", \"url\": \"/blog/create\", \"active\": false, \"attributes\": [], \"children\": [], \"depth\": 1 }\n        ],\n        \"depth\": 0\n    }\n]\n```\n\n```php\n// Append additional pages in your controller\nNavigation::make()-\u003eactiveSection()-\u003eadd($topic-\u003ename, route('blog.topics.show', $topic));\n\n// Render to breadcrumbs\nNavigation::make()-\u003ebreadcrumbs();\n```\n\n```json\n[\n    { \"title\": \"Blog\", \"url\": \"/blog\", \"attributes\": [] },\n    { \"title\": \"Topics\", \"url\": \"/blog/topics\", \"attributes\": [] },\n    { \"title\": \"Laravel\", \"url\": \"/blog/topics/laravel\", \"attributes\": [] }\n]\n```\n\n```php\n// Render the current section\nNavigation::make()-\u003ecurrent();\n```\n\n```json\n{ \"title\": \"Home\", \"url\": \"/\", \"attributes\": [] }\n```\n\n## Support us\n\n[\u003cimg src=\"https://github-ads.s3.eu-central-1.amazonaws.com/laravel-navigation.jpg?t=1\" width=\"419px\" /\u003e](https://spatie.be/github-ad-click/laravel-navigation)\n\nWe invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).\n\nWe highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require spatie/laravel-navigation\n```\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.\n\n## Security\n\nIf you've found a bug regarding security please mail [security@spatie.be](mailto:security@spatie.be) instead of using the issue tracker.\n\n## Credits\n\n- [Sebastian De Deyne](https://github.com/sebastiandedeyne)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Flaravel-navigation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspatie%2Flaravel-navigation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Flaravel-navigation/lists"}