This article will share with you a Laravel extension recommendation: Navigation element tool Laravel Navigation extension: Laravel extension recommendation: Navigation element tool Laravel Navigation Navigation package. It will introduce how to use Laravel extension recommendation: Navigation element tool Laravel Navigation Navigation to easily build site navigation elements. I hope it will be helpful to everyone!
Laravel extension recommendation: Navigation element tool Laravel Navigation Navigation is a package by Spatie for managing menus, breadcrumbs, and other navigation in Laravel extension recommendation: Navigation element tool Laravel Navigation applications Element.
While the Spatie Laravel extension recommendation: Navigation element tool Laravel Navigation Menu package is an Html menu generator for Laravel extension recommendation: Navigation element tool Laravel Navigation , but this package can be regarded as a "renderless component" of the navigation component:
app(Navigation::class) ->add('Home', route('home')) ->add('Blog', route('blog.index'), function (Section $section) { $section ->add('All posts', route('blog.index')) ->add('Topics', route('blog.topics.index')); }) ->addIf(Auth::user()->isAdmin(), function (Navigation $navigation) { $navigation->add('Admin', route('admin.index')); }); // 渲染到树结构 app(Navigation::class)->tree(); /* [ { "title": "Home", "url": "/", "active": false, "children": [] }, { "title": "Blog", "url": "/blog", "active": false, "children": [ { "title": "All posts", "url": "/blog", "active": false, "children": [] }, { "title": "Topics", "url": "/blog/topics", "active": true, "children": [] } ], }, { "title": "Admin", "url": "/admin", "active": false, "children": [] } ] */
Using this package, you can also use the following method to generate breadcrumbs from the navigation:
// 在你的控制器中添加额外的页面 app(Navigation::class)->activeSection()->add($topic->name, route('blog.topics.show', $topic)); // Render to breadcrumbs app(Navigation::class)->breadcrumbs(); /* [ { "title": "Blog", "url": "/blog" }, { "title": "Topics", "url": "/blog/topics" }, { "title": "Laravel extension recommendation: Navigation element tool Laravel Navigation", "url": "/blog/topics/laravel" } ] */
You can Learn about this package, get complete installation instructions, and view the source code on GitHub. Thanks to Sebastian De Deyne and the Spatie team for providing this package, and all the great open source PHP and Laravel extension recommendation: Navigation element tool Laravel Navigation packages like this one
Original address: https://laravel-news. com/laravel-navigation
Translation address: https://learnku.com/laravel/t/69041
[Related recommendations: laravel video tutorial]
The above is the detailed content of Laravel extension recommendation: Navigation element tool 'Laravel Navigation'. For more information, please follow other related articles on the PHP Chinese website!