Log1x / navi

A developer-friendly alternative to the WordPress NavWalker.
https://github.com/Log1x/navi
MIT License
315 stars 30 forks source link

Class 'Log1x\Navi\Facades\Navi' not found #36

Closed minemindmedia closed 3 years ago

minemindmedia commented 3 years ago

Hi, I am just getting started with Sage 10 after being a Sage 10 scaredy cat and I'm trying to use Navi.

I've registered a menu called navigation. I've looked through the issues and I'm following this ( https://github.com/Log1x/navi/issues/23 ) and the Sage 10 example but I'm getting the error below.

Class 'Log1x\Navi\Facades\Navi' not found 
(View: /srv/www/project.com/current/web/app/themes/cck/resources/views/partials/header.blade.php) 
(View: /srv/www/project.com/current/web/app/themes/cck/resources/views/partials/header.blade.php) 
(View: /srv/www/project.com/current/web/app/themes/cck/resources/views/partials/header.blade.php)

setup.php

    register_nav_menus([
        'navigation' => __('Navigation', 'sage')
    ]);

composers > navigation.php

<?php

namespace App\View\Composers;

use Roots\Acorn\View\Composer;
use Log1x\Navi\Facades\Navi;

class Navigation extends Composer
{
    /**
     * List of views served by this composer.
     *
     * @var array
     */
    protected static $views = [
        'partials.navigation',
    ];

    /**
     * Data to be passed to view before rendering.
     *
     * @return array
     */
    public function with()
    {
        return [
            'navigation' => $this->navigation(),
        ];
    }

    /**
     * Returns the primary navigation.
     *
     * @return array
     */
    public function navigation()
    {
        if (Navi::build()->isEmpty()) {
            return;
        }

        return Navi::build()->toArray();
    }
}

navigation.blade.php

@if ($navigation)
  <ul class="my-menu">
    @foreach ($navigation as $item)
      <li class="my-menu-item {{ $item->classes ?? '' }} {{ $item->active ? 'active' : '' }}">
        <a href="{{ $item->url }}">
          {{ $item->label }}
        </a>

        @if ($item->children)
          <ul class="my-child-menu">
            @foreach ($item->children as $child)
              <li class="my-child-item {{ $child->classes ?? '' }} {{ $child->active ? 'active' : '' }}">
                <a href="{{ $child->url }}">
                  {{ $child->label }}
                </a>
              </li>
            @endforeach
          </ul>
        @endif
      </li>
    @endforeach
  </ul>
@endif

header.blade.php

<header class="banner">
  <a class="brand" href="{{ home_url('/') }}">
    {{ $siteName }}
  </a>

  @include('partials/navigation')
Log1x commented 3 years ago

Is Navi installed inside of the theme? It should be on Sage 10.

minemindmedia commented 3 years ago

Hi, this is in the composer file in Sage 10:

  "require": {
    "php": "^7.3|^8.0",
    "roots/acorn": "dev-main",
    "log1x/navi": "^1.0",
    "log1x/sage-directives": "^1.1",
    "johnbillion/extended-cpts": "^4.5"
  },
fabianwurk commented 3 years ago

Did you try:

composer update

as that seems to be v1.0 and its currently on v2.0

minemindmedia commented 3 years ago

Yep, that was it. Changed it to 2.0 and updated. Thanks and sorry I missed that.