Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Milind24's avatar

Class 'App\Modelname' not found

I am setting a project on different server, but the issue I am facing is the for the namepsace. As on the previous server it was working fine. So, all my models are placed under "app/Models/", but the namespace used in models is "namespace App;" and when loading the models in controller "use App\Modelname;"..

When running the project it gives an error "Class 'App\Modelname' not found".

Any suggestions what could be the issue over here?

0 likes
3 replies
tykus's avatar

What does you autoload section of the composer.json file look like?

And alos, is the new server a case-sensitive filesystem; are you consistent with case between the directory / file names, and namespace / class names?

Milind24's avatar

The autoload section of composer.json: "autoload": { "psr-4": { "App\": "app/" }, "classmap": [ "database/seeds", "database/factories" ] },

tykus's avatar

@Milind24 so...

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

The correct namespace is App\Models\Modelname - because all my models are placed under "app/Models/" and that's how PSR-4 autoloading works!

Please or to participate in this conversation.