News

Blade Formatting in Laravel Pint

Published
Blade Formatting in Laravel Pint image

Pint 1.30.0 can format Laravel Blade templates, including blade syntax, Alpine Attributes, Tailwind class sorting, and more. Using the new --blade flag, it enables the configurable Pint/laravel_blade rule that runs your .blade.php files through Prettier and the prettier-plugin-blade plugin.

What's New

Blade Formatting With --blade

Point Pint at a project and add the flag:

./vendor/bin/pint --blade

The flag is a shortcut that toggles the Pint/laravel_blade rule, so you can turn it on permanently in pint.json instead:

{
"rules": {
"Pint/laravel_blade": true
}
}

When the rule is off, Pint excludes *.blade.php from its file finder entirely, which is the behavior every version before this one had. When it is on, only files ending in .blade.php go through the Blade formatter.

Formatting runs on Node, not PHP. The rule requires three npm packages, and Pint checks for them before it does any work:

  • prettier (^3.8.4)
  • prettier-plugin-blade (^3.2.2)
  • prettier-plugin-tailwindcss (^0.8.0)

If Node is missing, Pint aborts with an explanation. If the packages are missing, it detects your package manager, asks whether you want to install them, and installs each one pinned to the required constraint. If they are installed but the versions don't satisfy the constraints, Pint stops and prints the exact install command to fix it.

Three categories of Blade file are skipped even with the rule enabled, because reformatting them changes their output or their meaning:

  • Envoy task files (Envoy.blade.php, envoy.blade.php)
  • Boost guideline files under resources/boost/guidelines/
  • Mail views under resources/views/emails/ and resources/views/mail/

The test suite that shipped with the feature covers Alpine attributes, Livewire wire: bindings, Flux components, Tailwind class sorting, @verbatim blocks, heredocs, inline SVG, and single-file component classes, so the surface it handles is wider than plain HTML indentation.

Renamed Files in --diff

Pint's --diff option ran git diff with --diff-filter=AM, which matches added and modified files but not renames. A file you wrote and then renamed before pushing was silently skipped. The filter is now --diff-filter=AMR across the committed, staged, and unstaged diff commands.

PR: #448 by @MassimilianoLattanzio

--quiet Writes Issues to Stderr

--quiet was behaving like --silent: style violations were dropped rather than redirected. Issues now go to stderr, so stdout stays empty and the exit code still reflects the result, but you can read the list of offending files.

PR: #449 by @lazerg

in Key in pint.json

You can now restrict which directories Pint scans from the config file rather than passing paths on the command line, which makes porting a .php-cs-fixer.php config over more direct.

PR: #454 by @cosmastech

Upgrade Notes

No breaking changes for existing configurations. Blade formatting is opt-in, and with the rule disabled Pint treats .blade.php files exactly as it did before.

Update with Composer:

composer update laravel/pint

References

The source is on GitHub at laravel/pint.

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Filed in

Sponsored

masteringlaravel logo
Laravel Code Review

Get expert guidance in a few days with a Laravel code review

Visit Laravel Code Review

The latest

View all →
Laravel Read-Through Filesystem: Lazy Storage Migration image

Laravel Read-Through Filesystem: Lazy Storage Migration

Read article
Read-Through Disks and Debounced Listeners in Laravel 13.26 image

Read-Through Disks and Debounced Listeners in Laravel 13.26

Read article
Lerd: A Free, Open Source Herd Alternative for Linux and macOS image

Lerd: A Free, Open Source Herd Alternative for Linux and macOS

Read article
Let's Encrypt HTTPS on an IP Address With FrankenPHP image

Let's Encrypt HTTPS on an IP Address With FrankenPHP

Read article
Laravel Chores: Resumable Data Operations and Cleanups image

Laravel Chores: Resumable Data Operations and Cleanups

Read article
NativePHP v4: Build Native iOS and Android UI in Blade image

NativePHP v4: Build Native iOS and Android UI in Blade

Read article