laravel - "php artisan myCommand" handling the post-install-cmd event returned with error code 1
one text
Solution:
The problem is with the composer version, becase if you run any artisan command in post-install-cmd
or pre-install-cmd
it will run but some command ask input from user, just like mine as I describe in question that setupDb
will take input from user.
How I found the issue ?
I used an example of post-autoload-dump
that
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
was added in this event, I was thinking that for console command there should be something like this.
I try to add Illuminate\Console
in post-install-cmd
before artisan command and it return that it is deprecated with current composer version, So i updated my composer to v2, then it work like a charm.
Answer
So the answer will be that you need to update composer version to run post-install-cmd
custom commands like(setupDb)
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi"
],
"post-install-cmd": [
"php artisan setupDb",
"php artisan optimize"
]
}
and it will not return any error also it will ask input from user if any command require.
Source