PHP code example of bkoetsier / navigation

1. Go to this page and download the library: Download bkoetsier/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/ */

    

bkoetsier / navigation example snippets


// app/config/app.php

'providers' => [
    '...',
    'Bkoetsier\Navigation\Providers\Laravel\NavigationServiceProvider',
];

use Bkoetsier\Navigation\Navigation;
use Illuminate\Support\Collection;

$nav = new Navigation(new Bucket(new Collection));


$example = [
    [
        "id": 1,
        "content": '<a href="/books">Books</a>',
        "parent": null,
    ],
    [
        "id": 2,
        "content": '<a href="/books/fiction">Fiction</a>',
        "parent": 1,
    ]
];


// array to \Std
$data = json_decode(json_encode($example));

// with Laravel
Nav::fill($data, $itemIdentifier = 'id', $itemContent ='content',$parentIdentifier = 'parent');

//without Laravel
$nav->fill($data, $itemIdentifier = 'id', $itemContent = 'content',$parentIdentifier = 'parent');

//with Laravel
// set the current active item-id, maybe from a url or db
Nav::setCurrent(2);
Nav::menu('main')->render();

//without Laravel
$nav->setCurrent(2);
$nav->menu('main')->render();
 Nav::setCurrent()

Nav::menu('main')->setCurrent(1)->setMaxLevel(1);
Nav::menu('sub')->setCurrent(2);

//will render until level == 1 from id 1 down
Nav::menu('main')->render();
// will render from id 2 down until the end
Nav::menu('sub')->render();

//with Laravel
Nav::breadcrumbs()->render();

//without Laravel
$nav->breadcrumbs()->render();