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

twg_'s avatar
Level 6

Add task to Mix to call API

I'm currently using Laravel Mix to build my site css & js. After I build it I have to either upload it to my dev or prod site depending on what I'm doing.

Is there a way that I could call an API to upload the new JS & CSS to the correct instance so I can cut out a manual step?

0 likes
1 reply
piljac1's avatar

I do not know much about Mix since I started using it a couple of weeks ago, but I would personally try the following:

  1. Create a custom console command (php artisan) that would upload compiled files to the desired server
  2. Add it to your npm run dev / npm run watch commands in your package.json file (perhaps your command would have a param to indicate the destination site - dev or prod)
"scripts": {
    // "uploadToServer" would be the command name you choose of course

    "dev": "npm run development && php artisan uploadToServer dev",

    // other npm commands

    "prod": "npm run production && php artisan uploadToServer prod",

    // other npm commands
},
  1. Call "npm run dev" or "npm run prod" as usual, but now it will execute the command you created afterwards

Is it the best way to accomplish what you're trying to do ? I couldn't answer due to my limited Mix knowledge. Would it work ? There are pretty good chances that it would.

Please or to participate in this conversation.