PHP Storm and Laravel Pint
UPDATE AUGUST 2023
The latest version of PhpStorm, 2023.2, now includes support for Laravel Pint as part of its quality tools suite. This integration means that code style feedback from Laravel Pint seamlessly integrates with PhpStorm’s native code inspection feature.
To set up Laravel Pint within PhpStorm:
-
Navigate to
Settings > PHP > Quality Tools
and access the Laravel Pint subsection. -
If you’d like to utilize Laravel Pint as your primary code formatter, you can do so. By setting it as your external formatter, you can conveniently address all detected issues using the
Reformat Code ⌘⌥ L
function. -
To activate Laravel Pint as an inspection tool in PhpStorm, proceed to
Settings > Editor > Inspections
. Under thePHP | Quality Tools
section, tick the checkbox next to Laravel Pint validation.
Once this inspection tool is active, any inconsistencies found by Laravel Pint will be either highlighted directly in your PHP files or flagged in the ‘Problems’ tool window.
Manual method
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:
- Create a new File Watcher for Laravel Pint.
- Use the following settings for the file watcher:
- 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.
PHPStorm is formatting my code before Laravel Pint can run.
Disable PhpStorm’s built-in code formatting for PHP.