Here is your short guide on how to configure PhpStorm to run Laravel Pint on save to format your PHP files. I use this for every project to keep my PHP files clean.
Laravel Pint is installed upon creating a new Laravel project, so installing it might not be necessary. Check your composer.json
file to see if it's there.
If not, you can install Laravel Pint like so:
composer require laravel/pint --dev
Done? Let's roll.
In order to run Laravel Pint manually, you can run the following command:
./vendor/bin/pint
If you are like me, you don't want to run this command every time you want to format your files. Instead, let's configure PhpStorm so this command runs every time we hit the save button.
Open PhpStorm's settings (command + ,
) and go to Tools > Actions on Save > File Watcher > Configure
, and fill in the following fields:
Field | Value |
---|---|
File type | PHP |
Scope | Project Files |
Program | $ProjectFileDir$/vendor/bin/pint |
Arguments | $FileRelativePath$ |
Output paths to refresh | $FileRelativePath$ |
Working directory | $ProjectFileDir$ |
Trigger the watcher on external changes | Checked |
Finally, enable Reformat code
(make sure you exclude PHP files), Optimize imports
(optional), and Rearrange code
(optional).
When hitting save, Laravel Pint should now format your code.
If you have any questions or feedback, feel free to reach out to me.
Thanks,
Lars
If you are looking to have a website or web application built, feel free to reach out to me.
Copyright © 2024 Lars Wolters Software KVK 78342392 BTW NL003321256B95