简体   繁体   中英

Autoload folder without changing composer.json file - Laravel 5.4

I've created a package that creates a folder in the root of the project. Creating it in the app folder is for me not clean enough. Cause I don't want it to look like it's merged with the laravel framework. This package is for our company and will be used a lot.

So instead of changing the composer.json file everytime to add the folder to the autoloader I'm trying to just autoload it from the package.

Is something like that possible and how?

Are you saying that you do not want to add it in your composer.json file here?

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

That is what I would do.


What if you just use the folder structure as the autoloader namespace? That should work. For example:

<?php

use Company\Foo;

new Bar();

Where you would have a folder called company/Foo with all the classes inside declaring their namespace like so:

<?php

namespace Company\Foo;

class Bar {
    //
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM