How to load a new folder in Laravel 5 using composer.json?

I created a small application using Laravel 5.2. I saved all my work in the "Modules" folder located at App/Modules.

Now I am trying to move my folder Modulesto the root directory "outside the application folder". So, my folder is Modulesnow next to App.

I want to automatically load a folder Modules, as in a folder App.

To automatically load Modules, I modified myautoload section of mycomposer.json`, look like this:

"autoload": {
    "classmap": [
        "database"
    ],
    "psr-4": {
        "App\\": "app/",
        "Modules\\": "modules/"
    }
},

Also, in the configuration file, app.phpI added this service provider to my "providers" array

Modules\Vendname\Surveys\Providers\CoreValidatorServiceProvider::class,

Then from the command line I executed the following command

composer dumpautoload

, ,

FatalErrorException in ProviderRepository.php line 146: Class 'Modules\Vendname\Surveys\Providers\CoreServiceProvider' not found

CoreServiceProvider.php

<?php

namespace Modules\Vendname\Surveys\Providers;

use Illuminate\Support\ServiceProvider;

class CoreServiceProvider extends ServiceProvider
{

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {

        if (! $this->app->routesAreCached()) {
            require __DIR__ . '/../routes.php';
        }

    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {

    }

}

? ?

+4
1

- .

Modules\Vendname\Surveys\Providers\CoreValidatorServiceProvider::class,

app.php.

php artisan clear-compiled
composer dumpautoload
composer update

app.php

Modules\Vendname\Surveys\Providers\CoreValidatorServiceProvider::class,
+1

Source: https://habr.com/ru/post/1622545/


All Articles