Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

shipu's avatar
Level 2

Composer Script in laravel

How run my php class and artisan command after complete my package installation ? in my research composer script attribute do this for me but in my package not working this.

"scripts": {
      "post-install-cmd": [
        "Shipu\\Installer\\ComposerScripts::addFile",
        "php artisan vendor:publish --tag=public"
      ],
      "post-update-cmd": [
        "Shipu\\Installer\\ComposerScripts::addFile",
        "php artisan vendor:publish --tag=public"
      ]
    },
0 likes
8 replies
ricardovigatti's avatar

"Shipu\\Installer\\ComposerScripts::addFile", this is wrong.

When you create a command inside your package, there is a place to register the command, and you give a name to it. Something like mypackage::myaction.

The "post-install-cmd" at composer should be with that command instead of this namespace you're using...

TheNodi's avatar

@shipu

Composer post-x-cmd are fired like normal console commands. You should register your class as an artisan command and then use composer scripts to call them.

Example:

"scripts": {
      "post-install-cmd": [
        "php artisan installer:addfile",
        "php artisan vendor:publish --tag=public"
      ],
      "post-update-cmd": [
        "php artisan installer:addfile",
        "php artisan vendor:publish --tag=public"
      ]
    },
shipu's avatar
Level 2

@TheNodi no i don't want to make artisan comman... Are you sure Composer post-x-cmd are fired like normal console commands ?..... Please have a look in laravel composer.

shipu's avatar
Level 2

@ricardovigatti please have a look laravel composer. thank you. i want to call my class method. didn't want to make artisan command.

ricardovigatti's avatar

I saw it now. I tried to look into some files and figure out how this is working, but with no luck.

TheNodi's avatar

@shipu

So commonly used with shell script that I've never seen you can use static functions.

What kind of error does it gives you? Can you show your installer code? You probably cannot use most laravel functions (laravel isn't bootstrapped).

From composer documentation the method must be static and it'll receive an instance of Composer\EventDispatcher\Event (a subclass depending on the action). Nothing else seems required.

Try to run it manually to see if you get some debug information:

composer run-script post-install-cmd
shipu's avatar
Level 2

In installer code i just return a string "ok" ..

TheNodi's avatar

Have you tried echo-ing it or touch a file to see if it gets run? It should ignore the return value.

Please or to participate in this conversation.