Laravel psr-4 not autoloading

廉价感情. 提交于 2019-12-04 09:31:59

PSR-4 is indeed super-touchy about case, more so than Laravel itself. Full folder paths and names must be in the same case as the namespaces. The only places the cases don't need to be the same is where there's a reference in the PSR-4 section of composer.json.

This only becomes a problem with case-specific operating systems. I had no problems on my Mac, but CentOS refused to play.

Note this is different to the practice used for Laravel-specific framework across its documentation, which uses lowercase folder paths and CamelCase namespaces. This won't cause any problems on any operating system. July 2015 ETA: this info applied to Laravel 4; looks like Laravel 5 default folder structure adheres to psr-4 standards.

I eventually ended up with a folder structure like:

app/heatherland
  Import
    ImportJob.php

namespaces eg

HeatherLand\Import

and a composer.json entry as per the original question:

"autoload": {
    "classmap": [
        "app/commands",
        ...
        "app/database/seeds",
    ],
    "psr-4": {
        "HeatherLand\\": "app/heatherland"
    }
},

Note to self: Remember to run composer dump-autoload. Dump early, dump often.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!