Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rswfire's avatar

How to Move app/Nova Folder?

Hello,

I use a DDD structure for my application as described by Spatie's Laravel Beyond CRUD.

I would like to move the /app/Nova folder to /src/Domain/Laravel/Nova.

When I do this, I get the error:

The "app/Nova" directory does not exist.

I'm not sure what to do to solve this issue; can anyone help me?

Is it possible to move this folder?

Thank you for your time!

0 likes
13 replies
LaryAI's avatar
Level 58

To move the app/Nova folder to src/Domain/Laravel/Nova, you need to update the NovaServiceProvider to point to the new location.

  1. Move the app/Nova folder to src/Domain/Laravel/Nova.
  2. Open NovaServiceProvider.php located in app/Providers.
  3. Update the register method to point to the new location:
public function register()
{
    Nova::serving(function (ServingNova $event) {
        Nova::script('nova', __DIR__.'/../../src/Domain/Laravel/Nova/js/app.js');
        Nova::style('nova', __DIR__.'/../../src/Domain/Laravel/Nova/css/app.css');
    });
}
  1. Update the boot method to point to the new location:
public function boot()
{
    $this->loadViewsFrom(__DIR__.'/../../src/Domain/Laravel/Nova/resources/views', 'nova');

    $this->app->booted(function () {
        $this->routes();
    });
}
  1. Finally, update the composer.json file to autoload the new location:
"autoload": {
    "psr-4": {
        "App\": "app/",
        "Domain\Laravel\Nova\": "src/Domain/Laravel/Nova/src/"
    },
    "classmap": [
        "database/seeds",
        "database/factories"
    ]
},
  1. Run composer dump-autoload to update the autoloader.

Now you should be able to access Nova from the new location.

1 like
rswfire's avatar

This response has been very helpful, but I believe it may be for an earlier version of Nova.

I updated the register method to this because that's where Nova put the app.js/css files:

    public function register()
    {
        Nova::serving(function (ServingNova $event) {
            Nova::script('nova', $this->app->basePath().'/public/vendor/nova/app.js');
            Nova::style('nova', $this->app->basePath().'/public/vendor/nova/app.css');
        });
    }

And I updated the boot method to:

    public function boot()
    {
        Nova::resourcesIn($this->app->basePath().'/src/Domain/Laravel/Nova');

        $this->app->booted(function () {
            $this->routes();
        });
    }

I did this because there is no loadViewsFrom method in the parent class. The parent class had this:

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

So it seemed logical to point it to my new Nova folder.

Unfortunately, I get a 404 error when I try to visit the Nova frontend now.

At least I'm closer than I was!

I'd greatly appreciate any help.

rswfire's avatar

I'm happy to report I figured it out. I'll post the answer in case someone else needs this in the future:

NovaServiceProvider.php

<?php

namespace App\Providers;

use Illuminate\Support\Facades\Gate;
use Laravel\Nova\Events\ServingNova;
use Laravel\Nova\Nova;
use Laravel\Nova\NovaApplicationServiceProvider;

class NovaServiceProvider extends NovaApplicationServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        $this->gate();
        $this->routes();

        $this->app->booted(function () {
            $this->routes();
        });
    }

    /**
     * Register the Nova routes.
     *
     * @return void
     */
    protected function routes()
    {
        Nova::routes()
                ->withAuthenticationRoutes()
                ->withPasswordResetRoutes()
                ->register();
    }

    /**
     * Register the Nova gate.
     *
     * This gate determines who can access Nova in non-local environments.
     *
     * @return void
     */
    protected function gate()
    {
        Gate::define('viewNova', function ($user) {
            return in_array($user->email, [
                //emails
            ]);
        });
    }

    /**
     * Get the dashboards that should be listed in the Nova sidebar.
     *
     * @return array
     */
    protected function dashboards()
    {
        return [
            new \Domain\Laravel\Nova\Dashboards\Main,
        ];
    }

    /**
     * Get the tools that should be listed in the Nova sidebar.
     *
     * @return array
     */
    public function tools()
    {
        return [];
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        Nova::serving(function (ServingNova $event) {
            $this->authorization();
            $this->registerExceptionHandler();
            Nova::resourcesIn($this->app->basePath().'/src/Domain/Laravel/Nova');
            Nova::script('nova', $this->app->basePath().'/public/vendor/nova/app.js');
            Nova::style('nova', $this->app->basePath().'/public/vendor/nova/app.css');
            Nova::dashboards($this->dashboards());
            Nova::tools($this->tools());
        });
    }
}
rswfire's avatar

Well, it mostly works...

It loads up Nova, which is great.

Now I just need to figure out why the sidebar is empty.

gregupton's avatar

@rswfire have you had any luck with this? I'm trying to do the same thing and tried your answer and I'm still getting The "src/App/Nova" directory does not exist.

rswfire's avatar

@gregupton Hi. I have.

These are all in my custom nova service provider. Basically, I looked at the parent classes to see what they were responsible for and made sure that I included those in the new class; that made all the difference.

    public function boot()
    {
        $this->gate();
        $this->routes();

        $this->app->booted(function () {
            $this->routes();
        });
    }
// set this to your path; I use DIRECTORY_SEPARATOR because I work on Windows.
    protected function resources()
    {
        Nova::resourcesIn($this->app->basePath().DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'Domain'.DIRECTORY_SEPARATOR.'Laravel'.DIRECTORY_SEPARATOR.'Nova'.DIRECTORY_SEPARATOR.'Resources');
    }
    public function register()
    {
        Nova::serving(function (ServingNova $event) {
            $this->authorization();
            $this->registerExceptionHandler();
            Nova::resources([\Domain\Laravel\Nova\Resources\User::class]);
            Nova::script('nova', $this->app->basePath().'/public/vendor/nova/app.js');
            Nova::style('nova', $this->app->basePath().'/public/vendor/nova/app.css');
            Nova::dashboards($this->dashboards());
            Nova::tools($this->tools());
        });
    }

You may need to add this to composer.json as the bot suggested; I started with its steps and modified accordingly.

"Domain\Laravel\Nova\": "src/Domain/Laravel/Nova",

Of course, I'm using a different directory than you, so modify my answer for that as well! The only issue I have at this point is I think it may not auto-detect new classes (dashboards, resources, etc.) and I'll have to register all of them manually. I'm evaluating if I want to use Nova because of this. But the above definitely works; I'm serving Nova from a custom location.

martinbean's avatar

It amazes me how many people think “DDD” is “let’s put things in directories under a ‘Domain’ directory.”

rswfire's avatar

@martinbean, thanks for your very helpful response. It amazes me when someone feels the need to talk down to others.

We can't control Nova. The best we can do is move it somewhere that makes more sense than a default folder we don't even use.

martinbean's avatar

We can't control Nova. The best we can do is move it somewhere that makes more sense than a default folder we don't even use.

@rswfire Except for when you are using it… to house Nova?

rswfire's avatar

@martinbean, what is wrong with you? Are you here to discourage people from seeking help with their issues?

martinbean's avatar

@rswfire Not at all. I’m just trying to steer you in the direction that, when it comes to DDD, Nova is an application concern and belongs nowhere in your “Domain” directory.

rswfire's avatar

@martinbean, and you think that's what you accomplished with your comments, really? Why not explain your thoughts and say, "How about placing this in another directory?" Apologize, because you're rude, and I'm canceling Nova because I won't seek support from it here when this is is the reception I've received. Also, it's not just an application concern. It's both. That's what makes it more difficult to decide where to place it. It has logic for both. It doesn't belong in the "Application" directory either. Frankly it belongs in its own src directory. But none of that was the point of this post. The point was to move it. What we do with it is our business.

Please or to participate in this conversation.