samedi 2 janvier 2016

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

I created a small app using Laravel 5.2. I kept all of my work inside a folder called "Modules" located in App/Modules.

Now, I am trying to move out my Modules folder to the root directory "outside the App folder." So my Modules folder is now located next to the App.

I want to auto load the Modules folder just like the App folder.

To auto load the Modules, I modified myautoloadsection of mycomposer.json` to look like the following:

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

Additionally, in the app.php config file I 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

Every time I go to the website, I get this error

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

Here is the code for my CoreServiceProvider.php file

<?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()
    {

    }

}

What am I doing wrong here? What do I need to do in order to properly auto load the new folder?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire