PHP code example of felixdorn / laravel-navigation

1. Go to this page and download the library: Download felixdorn/laravel-navigation library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

felixdorn / laravel-navigation example snippets


use Felix\Navigation\Navigation;

Navigation::register('dashboardSidebar', function (Navigation $navigation) {
    
});

use Felix\Navigation\Navigation;

Navigation::dashboardSidebar()->toArray();
// alternatively, to get the raw tree underneath:
Navigation::dashboardSidebar()->tree();

use Felix\Navigation\Item;

$navigation->addIf($isAdmin, 'Settings', function (Item $item) {
    // ...
});
$navigation->addUnless($isReader, 'Articles', function (Item $item) {
    // ...
});

use Felix\Navigation\Item;
use Felix\Navigation\Section;

$navigation->addSection('Name', function (Section $section) {
    $section->add('Child', function (Item $item) {
        // ...
    });
});

use Felix\Navigation\Section;

$navigation->addSectionIf($isAdmin, 'Admin', function (Section $section) {
    // ...
});
$navigation->addSectionUnless($isReader, 'Bookmarks', function (Section $section) {
    // ...
});

/** @var \Felix\Navigation\Item $item **/
$item->route('articles.index');

$item->route('tenant.show', ['tenant' => 1]);

$item->url('https://github.com/felixdorn')

$item->route('articles.index')
    ->activeWhenRouteMatches('articles.*') // active for articles.index / articles.edit / articles.anything

$item->meta(['a' => 'b']);
// same as
$item->a('b');