3

I have a brand new installation of Laravel Nova. The dashboard comes up fine. But when I add a new resource using php artisan nova:resource Post and reload the dashboard, it's throwing an error. When I remove the offending model from Nova folder, dashboard works again. I'm following the step by step instructions from the Nova docs exactly. I can't figure it out.

Screenshot Screenshot

navigation.blade.php

@if (count(Nova::availableResources(request())))
    <h3 class="flex items-center font-normal text-white mb-6 text-base no-underline">
        <svg class="sidebar-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20">
            <path fill="var(--sidebar-icon)" d="M3 1h4c1.1045695 0 2 .8954305 2 2v4c0 1.1045695-.8954305 2-2 2H3c-1.1045695 0-2-.8954305-2-2V3c0-1.1045695.8954305-2 2-2zm0 2v4h4V3H3zm10-2h4c1.1045695 0 2 .8954305 2 2v4c0 1.1045695-.8954305 2-2 2h-4c-1.1045695 0-2-.8954305-2-2V3c0-1.1045695.8954305-2 2-2zm0 2v4h4V3h-4zM3 11h4c1.1045695 0 2 .8954305 2 2v4c0 1.1045695-.8954305 2-2 2H3c-1.1045695 0-2-.8954305-2-2v-4c0-1.1045695.8954305-2 2-2zm0 2v4h4v-4H3zm10-2h4c1.1045695 0 2 .8954305 2 2v4c0 1.1045695-.8954305 2-2 2h-4c-1.1045695 0-2-.8954305-2-2v-4c0-1.1045695.8954305-2 2-2zm0 2v4h4v-4h-4z"
            />
        </svg>
        <span class="sidebar-label">{{ __('Resources') }}</span>
    </h3>

    @foreach(Nova::groupedResources(request()) as $group => $resources)
        @if (count($resources) > 0)
            @if (count(Nova::groups(request())) > 1)
                <h4 class="ml-8 mb-4 text-xs text-white-50% uppercase tracking-wide">{{ $group }}</h4>
            @endif

            <ul class="list-reset mb-8">
                @foreach($resources as $resource)
                    @if (! $resource::$displayInNavigation)
                        @continue
                    @endif

                    <li class="leading-tight mb-4 ml-8 text-sm">
                        <router-link :to="{
                            name: 'index',
                            params: {
                                resourceName: '{{ $resource::uriKey() }}'
                            }
                        }" class="text-white text-justify no-underline dim">
                            {{ $resource::label() }}
                        </router-link>
                    </li>
                @endforeach
            </ul>
        @endif
    @endforeach
@endif

I see that the Blade is calling @foreach($resources as $resource), which is where I assume the code is failing. The docs say:

"Automatic Registration -- By default, all resources within the app/Nova directory will automatically be registered with Nova. You are not required to manually register them. Before resources are available within your Nova dashboard, you must register them with Nova. Resources get registered in your app/Providers/NovaServiceProvider.php file. This file contains various configuration and bootstrapping code related to your Nova installation."

But when I look at app/Providers/NovaServiceProvider.php there are no resources listed:

<?php
namespace App\Providers;

use Laravel\Nova\Nova;
use Laravel\Nova\Cards\Help;
use Illuminate\Support\Facades\Gate;
use Laravel\Nova\NovaApplicationServiceProvider;

class NovaServiceProvider extends NovaApplicationServiceProvider
{
    public function boot()
    {
        parent::boot();
    }

    protected function gate()
    {
        Gate::define('viewNova', function ($user) {
            return in_array($user->email, [
                //
            ]);
        });
    }

    protected function cards()
    {
        return [
            new Help,
        ];
    }

    public function tools()
    {
        return [];
    }
}

Unfortunately, when I paste in the suggested code for manually registering the resources, it still doesn't work.

<?php

use App\Nova\User;
use App\Nova\Post;

protected function resources()
{
    Nova::resourcesIn(app_path('Nova'));

    Nova::resources([
        User::class,
        Post::class,
    ]);
}
6
  • can you post you navigation.blade.php? Commented Nov 21, 2018 at 4:02
  • I just found you a possible fix . Take a look here github.com/laravel/nova-issues/issues/55 Commented Nov 21, 2018 at 4:06
  • Thanks Dearwolves. I saw that post. Didn't help, unfortunately. Commented Nov 21, 2018 at 18:18
  • navigation.blade.php posted above Commented Nov 21, 2018 at 18:18
  • Here's the deal. There is a file called User.php in the App directory - NOT THE ONE IN THE App/Nova directory where the resource is created. But actually in the App directory. When you create a new resource, you have to create a duplicate of this file with the name of your resource. So in my case, copy the file and create Images.php in the App directory. This fixes the issue. Artisan does NOT create this file automatically. Commented Nov 21, 2018 at 21:37

4 Answers 4

4

Yes, the missed up an App\Post model creation and migration with title and body:

php artisan make:model Post -m

Also add to posts migration if you are from LaraCasts tutorial:

    $table->char('title', 100);
    $table->text('body');

Execute the migrate Artisan command:

php artisan migrate

After you can create resource in App/nova folder:

php artisan nova:resource Post
Sign up to request clarification or add additional context in comments.

Comments

3

Yes, the missed up an App\Post model creation and migration with title and body

php artisan make:model Post -m

Also add to posts migration if you are from LaraCasts tutorial

$table->char('title', 100);
$table->text('body');

Comments

0

First create new Model for post (m for migration)

php artisan make:model Post -m 

After you can create resource in app/nova folder

php artisan nova:resource Post

Comments

0

You need to create the model before the resource :

php artisan make:model ModelName

then

php artisan make:resource ResourceName

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.