ammezie
ammezie

Reputation: 355

Key is a duplicate in ./composer.json

Am trying structure my app in such a way that all my models will be in a dedicated directory(in my case Classified). I created the directory with Laravel app directory and added it to my my composer.json file. Below is the structure of my composer.json file:

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

Then I run composer dump-autoload in my terminal but I keep getting "Key Classified\ is a duplicate in ./composer.json at line 29 " and when I tried viewing my app in the browser i get:

Fatal error: Uncaught exception 'ReflectionException' with message 'Class App\Http\Kernel does not exist' in /home/vagrant/Workspace/codulabproducts/classified/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 736.

Line 29 in my composer.json file is

"Classified\\": "app/Classified"

I don't know what am doing wrong because I have followed these steps in my other project and everything went well.

Upvotes: 5

Views: 6298

Answers (2)

xabbuh
xabbuh

Reputation: 5881

You can define more than one directory for a namespace prefix. But in that case the value for the key must be a list and not a string (see the second example in the documentation):

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

Upvotes: 10

jedrzej.kurylo
jedrzej.kurylo

Reputation: 40909

You can't have duplicated keys in your psr-4 mapping. It is supposed to define the root folder for given namespace and a namespace cannot have multiple roots.

Remove one of the mappings for Classified\ namespace.

Upvotes: 3

Related Questions