I wrote a Laravel package that I want to make available for everyone to download.
However, it seems that I have to manually execute composer dump-autoload
after I add my package.
Is it possible to automatically execute composer dump-autoload
after the install so that the composer will autoload all the new classes in my project?
If you need to regenerate your package's autoload files, you may use the php artisan dump-autoload command. This command will regenerate the autoload files for your root project, as well as any workbenches you have created.
composer install is primarily used in the 'deploying phase' to install our application on a production server or on a testing environment, using the same dependencies stored in the composer. lock file created by composer update.
To update Composer itself to the latest version, run the self-update command. It will replace your composer.phar with the latest version. If Composer was not installed as a PHAR, this command is not available. (This is sometimes the case when Composer was installed by an operating system package manager.)
Yes, you can add it in the "post-update" script section of your composer.json
. It'll then be executed after every update of the project. You can also add it inside the "post-install" section, so the command will be called directly after the installation.
A short excerpt from a composer.json:
"scripts": {
"post-root-package-install": [
"php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
],
"post-install-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postInstall",
"composer dump-autoload", // Here.
"php artisan optimize"
],
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
"composer dump-autoload" // Here too.
]
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With