Hello everyone,
I'd like to ask a few questions about autoload in composer.json. I was looking into this tutorial on publishing my own package to packagist... and got confused with what autoload in composer.json does.
https://pusher.com/tutorials/publish-laravel-packagist
Here are my questions...
A. What does autoload (espcially psr-4) in Laravel do in the background?
B. Why should each package have its own autoload psr-4? What is this for?
ex)
"autoload": {
"psr-4": {
"MyVendor\contactform\": "src/"
}
}
C. Why do we add another autoload psr-4 to Laravel's composer.json? What is this for?
ex)
"autoload": {
"classmap": [
"database/seeds",
"database/factories"
],
"psr-4": {
"MyVendor\Contactform\": "packages/MyVendor/contactform/src",
"App\": "app/"
}
}
D. What's the relationship between this and the service provider list in config/app.php? It looks like I still need to add the custom package's service provider to app.php anyway. Then, what's the point of doing 'autoload'?
// config/app.php
'providers' => [
...,
App\Providers\RouteServiceProvider::class,
// Our new package class
MyVendor\Contactform\ContactFormServiceProvider::class,
],
Please enlighten me...
Thanks!