Laravel-Backpack/MenuCRUD

Class 'Backpack\MenuCRUD\app\Models' not found

shinokada opened this issue · 8 comments

What I did:

I used method B to install MenuCRUD.
I successfully added some menus in Backpack.
In the front end, I followed the doc.

I have the following code:

<!-- Navigation -->
<nav id="menu" class="menu-main-menu-container" aria-label="Navigation" itemscope itemtype="https://schema.org/SiteNavigationElement">
    <ul id='menu-main-menu' class='menu'>
        @foreach (Backpack\MenuCRUD\app\Models::getTree(); as $item)
        <a class="no-underline hover:underline p-3"
        href="{{$item->url()}}">
        {{ $item->name }}
        </a> 
        @endforeach 
    </ul>
</nav>
<a class="responsive-menu-toggle" href="#"><i class='fa fa-reorder'></i></a>

What happened:

It returns an error:

Error
Class 'Backpack\MenuCRUD\app\Models' not found (View: /Applications/MAMP/htdocs/codewithshin-laravel/resources/views/pages/partials/navigation.blade.php)

Backpack, Laravel, PHP, DB version:

Backpack: v4
Laravel: 8.40.0
PHP: 7.4.12
DB: 5.7.32 - MySQL Community

pxpm commented

Hello @shinokada

Easy to spot error. @foreach (Backpack\MenuCRUD\app\Models::getTree(); as $item) should be @foreach (Backpack\MenuCRUD\app\Models\Menu::getTree(); as $item)

I am going to close this as I think there is no bug here.

Best,
Pedro

@pxpm Thank you for your reply.
But I still get an error.

image

pxpm commented

@shinokada use \Backpack ... note the backslash before Backpack.

Yes, I have it.

image

pxpm commented

Sorry, my bad, the name is MenuItem and not Menu. \Backpack\MenuCRUD\app\Models\MenuItem

Best,
Pedro

@pxpm Thank you for your help.
Shouldn't the doc be updated?

pxpm commented

@shinokada totally. Where in docs did you found it ? I only found in README.md and it's correct.

image

Can you point me where you saw it was incorrect ?

Thanks,
Pedro

It must be my mistake then.

But when I use \App\MenuItem::getTree(), I get an error though.