PHP code example of dewsign / nova-navigation

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

    

dewsign / nova-navigation example snippets


// app/Nova/HeaderNavigation.php

namespace App\Nova;

use Dewsign\NovaNavigation\Nova\Navigation;

class HeaderNavigation extends Navigation
{
    public static $zone = 'header';

    public static function label()
    {
        return __('Header Links');
    }
}

@novaNavigation('my-zone')

<ul>
    @foreach ($items as $item)
        <li>
            {!! $item->view !!}
            @if ($item->navigations->count())
                @novaNavigation($zone, $item->navigations)
            @endif
        </li>
    @endforeach
</ul>

@foreach($navigationItem->navigations as $item)
    {!! $item->view !!}
@endforeach

<a href="{{ $navigationItem->action }}">{{ $navigationItem->label }}</a>

// app/Navigation/Models/Category.php

use Dewsign\NovaNavigation\Models\NavigationItem;

class Section extends NavigationItem
{
    public static $viewTemplate = 'nova-navigation::category';

    public function category()
    {
        // BlogCategoryModel is used as an example. Include your actual blog category model.
        return $this->belongsTo(BlogCategoryModel::class);
    }

    // Return the url for this navigation item
    public function resolveAction()
    {
        return route('blog.category', $this->category);
    }

    // Return the label to display in the navigation
    public function resolveLabel($category = null)
    {
        // Automatically use the category title as navigation label
        return $category->title;
    }
}

// database/migrations/your_migration.php

Schema::create('nav_categories', function (Blueprint $table) {
    $table->increments('id');
    $table->integer('category_id')->nullable();
    $table->timestamps();
});

// app/Navigation/Nova/Category.php

...
use Dewsign\NovaNavigation\Nova\Items\NavigationItem;

class Section extends NavigationItem
{
    // The model we just created
    public static $model = App\Navigation\Models\Category::class;

    public static function label()
    {
        return __('Category');
    }

    public function fields(Request $request)
    {
        return [
            // BlogCategoryResource is used as an example. Include your actual blog category nova resource.
            BelongsTo::make('Category', 'category', BlogCategoryResource::class)->searchable(),
        ];
    }
}

<a href="{{ $model->action }}" class="category-navigation-item">{{ $model->label }}</a>

<a href="{{ $model->action }}" class="category-navigation-item">
    {{ $model->label }} ({{ $model->category->articles()->count() }})
</a>

return [
    "repeaters" => [
        \App\Navigation\Nova\Category::class,
    ],
    "replaceRepeaters" => false,
];

    // config/repeater-blocks
    ...
    "repeaters" => [
        ...
        Dewsign\NovaNavigation\Nova\NrbHyperlinks::class,
    ],