Home > PHP Framework > Laravel > body text

Laravel extension recommendation: Navigation element tool 'Laravel Navigation'

青灯夜游
Release: 2022-11-23 20:41:50
forward
1249 people have browsed it

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'

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.

Laravel extension recommendation: Navigation element tool Laravel Navigation

Tweet address

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": [] }
]

*/
Copy after login

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" }
]
*/
Copy after login

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!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!