3

Trying the following config to load my models from root namespace failed. any alternative?

"autoload": {
    "psr-4": {
      "\\": "app/Models"
    }
  },

The following works but I have to run dumpautoload each time I create a new class.

"classmap": [
      "app/Models"
    ],

Any suggestion?

Handsome Nerd
  • 17,114
  • 22
  • 95
  • 173

1 Answers1

1

Instead of "\\", you should map "" to "app/Models". Quoting from composer docs:

If you want to have a fallback directory where any namespace will be looked for, you can use an empty prefix like:

{
    "autoload": {
        "psr-4": { "": "src/" }
    }
}

So, in your case:

{ 
   "autoload": {
        "psr-4": {
          "": "app/Models"
        }
     }
}
Nima
  • 3,309
  • 6
  • 27
  • 44