• Reading time ~ 1 min
  • 01.06.2023

If you want Laravel Pint to reformat your PHP code automatically when you save your file in PhpStorm, you can set it up as a file watcher and run it as an “action on save”. To do this, you need to disable PhpStorm’s built-in code formatting for PHP.

Follow these steps to set up Laravel Pint as a file watcher in PhpStorm:

  1. Create a new File Watcher for Laravel Pint.

PHP Storm and Laravel Pint settings

  1. Use the following settings for the file watcher:

PHP Storm and Laravel Pint settings

  • Program: $ProjectFileDir$/vendor/bin/pint
  • Arguments: $FileRelativePath$
  • Output paths to refresh: $FileRelativePath$
  • Working directory: $ProjectFileDir$

To ensure it’s functioning correctly during setup, you can enable the “Always” option. Following that, my preference is for “On error.”


Troubleshooting

Got an error in macOS: “env: php: No such file or directory”

If you’re using newer macOS systems, you may have encountered an issue with PHPStorm where it cannot find the PHP binary to execute. This is because PHP is no longer included on newer macOS versions. However, if you have Brew installed, you can easily resolve this issue by adding the Brew version of PHP to the path /usr/local/bin. By doing so, you’ll be able to use PHPStorm without any problem and continue working on your PHP projects.

Add path

PHPStorm is formatting my code before Laravel Pint can run.

Disable PhpStorm’s built-in code formatting for PHP.

Disable PHPStorms code formatting

Comments

No comments yet
Yurij Finiv

Yurij Finiv

Full stack

ABOUT

Professional Fullstack Developer with extensive experience in website and desktop application development. Proficient in a wide range of tools and technologies, including Bootstrap, Tailwind, HTML5, CSS3, PUG, JavaScript, Alpine.js, jQuery, PHP, MODX, and Node.js. Skilled in website development using Symfony, MODX, and Laravel. Experience: Contributed to the development and translation of MODX3 i...

About author CrazyBoy49z
WORK EXPERIENCE
Contact
Ukraine, Lutsk
+380979856297