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

mikebronner's avatar

Have Package automatically run its Migrations when being installed or updated?

Is it possible to do this? I want to take as much burden off of the user for the setup process, and especially for updating the package.

I envision the package running its migrations then seeders when installing it via composer. Any suggestions on how to do that?

0 likes
2 replies
xingfucoder's avatar

Hi @mikebronner, edit your package composer.json file and you can find something as follow in the Laravel composer.json included:

"scripts": {
  "post-install-cmd": [
   "php artisan clear-compiled",
   "php artisan route:scan",
   "php artisan event:scan",
   "php artisan optimize"
  ],
  "post-update-cmd": [
   "php artisan clear-compiled",
   "php artisan optimize"
  ],
  "post-create-project-cmd": [
   "php artisan key:generate"
  ]
 },

The scripts are commands that you could run in the install, update or another.

Creating your custom comand or running your php artisan migrate custom command you should get it.

Hope it helps you.

1 like
mikebronner's avatar

Hi @codeatbusiness :) Thanks again. Yes, I have been playing with that, and think it works ... but have not gotten far enough to test it yet (my package is still in workbench -- which is also why I haven't updated the post yet). If it does end up working, I'll be sure to mark your answer, though. :)

Please or to participate in this conversation.