Josip Codes
Josip Codes

Reputation: 9521

Laravel config subfolder not recognized on new server

I have some config files of US state counties, for example:

config/
    state/
        alabama/
            counties.php
        alaska/
            counties.php
        ...

And on my development localhost server, I call them with:

Config::get('state/alabama/counties');

and it works, it loads an array of counties which I display somewhere.

But when I deploy this app on the Heroku, they won't show up. I was thinking that it maybe has a problem with treating the config/state/subfolder as an environment config?

I do have a config/staging subfolder, in which I have new DB config stuff, and it works with no problem, but on the Heroku app, the states just won't show up.

Upvotes: 0

Views: 428

Answers (1)

James Binford
James Binford

Reputation: 2883

Have you added this directory to your autoload mapping in composer.json and then run composer dump-autoload? Without this, Laravel doesn't know to load your new files in to consideration.

Composer is a CLI-run file that exists in the Root of each laravel installation. composer.json is the config file for Composer - it uses this to manage your dependencies.

There's a section in composer.json called "autoload." These are the files that will automatically be loaded each time the app boots. Mine looks like this:

"autoload": {
        "classmap": [
            "app/commands",
            "app/controllers",
            "app/database/migrations",
            "app/database/seeds",
            "app/tests/TestCase.php",
            "app/core"
        ]

For each folder that didn't exist before and that I wanted Laravel to understand, I added an entry here. Then, I ran composer dump-autoload and Laravel "understood" where the files I wanted to use were.

Each time you add a file, class, repository - anything that you want Laravel to automatically use, you'll have to run composer dump-autoload.

P.S: If composer dump-autoload doesn't work, try composer.phar dump-autoload.

Upvotes: 1

Related Questions