Laravel Pint

Published on by

Laravel Pint image

The long-awaited hype train is finally over, Laravels latest open source CLI app has been released to the world, and we got our hands on it to tell you all about it. Introducing Laravel Pint ...

From the readme, "Laravel pint is a zero-dependency PHP code style fixer for minimalists - built on top of PHP-CS-Fixer."

As soon as I read this, I got excited, and I mean very excited. In modern PHP, we have been going through a phase of honing our craft, making our code stricter and better tested, and ensuring we have a consistent code style. This all began back when PHP-FIG was formed, and they started to release PSRs, and it been going from strength to strength with frameworks having their own specific published style rules. This package is no different and will automatically test and fix your code style based on a preset.

To get started with this package, install it using composer:

composer require laravel/pint --dev

Once installed, it will just run with no configuration required. So you can run:

./vendor/bin/pint

With no configuration, no setup, or thought or effort - my project is instantly assessed for PSR-12 styling and automatically fixed. Magical. Keeping your code clean and consistent sometimes takes effort or thought on how to get this setup - which rules you need to implement. Or with PHP CS Fixer, you had to create a config file, then go through and create a finder to add rules to a PHP file in an array. Things got messy quickly, right?

No more. If you create a pint.json file in the root of your project, it will simply load this and read the configuration - otherwise, stick to its defaults. The configuration is all done using JSON, making it much easier to use and more readable.

Let's take a quick look at setting up a new pint config using a preset. But let's have a look at doing it with a fresh new Laravel project, so create a new project:

laravel new pint-demo

Open this new project in your terminal and install pint:

composer require laravel/pint --dev

With our brand new Laravel application, let's configure a preset to Laravel. Create a pint.json file and add:

{
"preset": "laravel"
}

Now run pint:

./vendor/bin/pint

You should see an output similar to the below:

We have lift off 🚀

So let's now change our preset to PSR-12 and check the output:

{
"preset": "psr12"
}

Rerun pint and let's see the output:

./vendor/bin/pint

You should see the following output:

Let's inspect this a little. It has implemented rules like single_trait_insert_per_statement and braces and new_with_braces. What if we want to customize these a little? Well, we can turn rules on and off really easily. Let's turn off braces in our pint.json file:

{
"preset": "psr12",
"rules": {
"braces": false
}
}

That is it! It is simple to customize how you want to set up your code styles. No more messy PHP and arrays to configure your coding style. So let us rerun pint, but this time we want to do a dry run to see what will be changed:

./vendor/bin/pint —test

Awesome right? Nice clean output, doing a dry run, seeing what will fail and why! So what happens if we want a little more information? I have fixed the files above and gone back to the user migration - and undone those changes so we can test it out. Let's do a dry run again, but this time we want to ask for verbose output using the -v flag:

We get excellent output, much like when using GitHub, of the changes that would be made. So we can see the code style issue, what it is being caught on, and what changes would happen if we fixed it - all from using one pretty simple command.

I don't know about you, but this is a must-install for all of my upcoming projects, packages, and anything else I work on.

Steve McDougall photo

Educator and Content creator, freelance consultant, API evangelist

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.

Laravel Forge logo

Laravel Forge

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Forge
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $7500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
Cut PHP Code Review Time & Bugs into Half with CodeRabbit logo

Cut PHP Code Review Time & Bugs into Half with CodeRabbit

CodeRabbit is an AI-powered code review tool that specializes in PHP and Laravel, running PHPStan and offering automated PR analysis, security checks, and custom review features while remaining free for open-source projects.

Cut PHP Code Review Time & Bugs into Half with CodeRabbit
Laravel Idea for PhpStorm logo

Laravel Idea for PhpStorm

Ultimate PhpStorm plugin for Laravel developers, delivering lightning-fast code completion, intelligent navigation, and powerful generation tools to supercharge productivity.

Laravel Idea for PhpStorm
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Bacancy logo

Bacancy

Supercharge your project with a seasoned Laravel developer with 4-6 years of experience for just $2500/month. Get 160 hours of dedicated expertise & a risk-free 15-day trial. Schedule a call now!

Bacancy
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
Lunar: Laravel E-Commerce logo

Lunar: Laravel E-Commerce

E-Commerce for Laravel. An open-source package that brings the power of modern headless e-commerce functionality to Laravel.

Lunar: Laravel E-Commerce
LaraJobs logo

LaraJobs

The official Laravel job board

LaraJobs
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
Supercharge Your SaaS Development with FilamentFlow: The Ultimate Laravel Filament Boilerplate logo

Supercharge Your SaaS Development with FilamentFlow: The Ultimate Laravel Filament Boilerplate

Build your SaaS application in hours. Out-of-the-box multi-tenancy and seamless Stripe integration. Supports subscriptions and one-time purchases, allowing you to focus on building and creating without repetitive setup tasks.

Supercharge Your SaaS Development with FilamentFlow: The Ultimate Laravel Filament Boilerplate
JetShip - Laravel Starter Kit logo

JetShip - Laravel Starter Kit

A Laravel SaaS Boilerplate and a starter kit built on the TALL stack. It includes authentication, payments, admin panels, and more. Launch scalable apps fast with clean code, seamless deployment, and custom branding.

JetShip - Laravel Starter Kit
Rector logo

Rector

Your partner for seamless Laravel upgrades, cutting costs, and accelerating innovation for successful companies

Rector
MongoDB logo

MongoDB

Enhance your PHP applications with the powerful integration of MongoDB and Laravel, empowering developers to build applications with ease and efficiency. Support transactional, search, analytics and mobile use cases while using the familiar Eloquent APIs. Discover how MongoDB's flexible, modern database can transform your Laravel applications.

MongoDB

The latest

View all →
Laracon EU Amsterdam 2025 image

Laracon EU Amsterdam 2025

Read article
Collection Customization in Laravel Using CollectedBy image

Collection Customization in Laravel Using CollectedBy

Read article
Laravel Faker OpenAI image

Laravel Faker OpenAI

Read article
Accessing Locale and Currency Defaults in Laravel image

Accessing Locale and Currency Defaults in Laravel

Read article
UseFactory Attribute Added in Laravel 11.39 image

UseFactory Attribute Added in Laravel 11.39

Read article
Laravel SpaceOCR: Parse Images and Multi-page PDFs in Laravel image

Laravel SpaceOCR: Parse Images and Multi-page PDFs in Laravel

Read article