Reputation: 520
I have developed API using Lumen framework and using separately created composer package which I'm planning to use both on Lumen (API) and Laravel (Web site).
However I get:
Class 'Author\Package\Models\ProductItem' not found
Locally everything is working (using same Apache and PHP version). My directory structure is:
|
\_ api (Lumen code)
|
\_ model\
| \_ src\
| | \_ migrations\
| | |
| | \_ models\
| | | \_ ProductItem.php
| | |...
| |
| \_ composer.json
|
\_ www (Laravel code)
in api\composer.json
I have:
...
"autoload": {
"psr-4": {
"App\\": "app/",
"Author\\Package\\": "../model/src"
}
},
...
Only difference between local and hosting configuration is version of Composer (local is 1.5.2 and remote is 1.4.2).
Upvotes: 1
Views: 763
Reputation: 17166
Your namespace or your PSR-4 mapping is incorrect.
When your class contains Models
with uppercase M in its namespace Author\Package\Models\ProductItem
it should be located in ./model/src/Models/ProductItem.php
(also uppercase M). So both namespace and folder name must match exactly. On Windows/Mac this is usually not a problem, because the filesystem is case-insensitive, but on a Linux-based host this will cause problems.
Alternatively you can change your PSR-4 autoloader:
"autoload": {
"psr-4": {
"Author\\Package\\Models\\": "../model/src/models"
}
}
You would have to do that for every directory that does not match your namespace.
Upvotes: 4