how to fix and clean code style  in laravel 9

In this section we will see how fix laravel 9 code and clean and  PHP-CS-Fixer style. We can use Laravel Pint package to fix our code style stays clean and consistent.  Laravel Pint is an opinionated PHP code style fixer for minimalists. Pint is built on top of PHP-CS-Fixer and makes it simple to ensure that your code style stays clean and consistent.


#Requirement

PHP 8.0+

Laravel 9


Install pint you laravel 9 project

composer require laravel/pint --dev


Once Pint has been installed, the pint binary will be available in your project's vendor/bin directory:

Before run pint

public function index()
{
    $categories = Category::latest()->paginate(10);
    return view('category.index', compact('categories'));
}


After run ./vendor/bin/pint

./vendor/bin/pint
laravel 9 fix code style

laravel 9 fix code style

After run pint

public function index()
{
    $categories = Category::latest()->paginate(10);
    
    return view('category.index', compact('categories'));
}


laravel Running Pint

When running Pint, it will output a list of files that have been fixed. It is possible to see the changes made in more detail using the -v option:

./vendor/bin/pint -v


In addition, if you would like Pint to simply inspect your code for style errors without actually changing the files, you may use the --test option:

./vendor/bin/pint --test


For details vist https://github.com/laravel/pint


Read Also

Laravel 9 Add Simple Sidebar with Tailwind CSS Example

How to Use Carousel Slider in Laravel 9 Example

Laravel 9 Posts with Tags Many to Many Relationships Example

Laravel 9 Insert Category in Posts CRUD Example

How to Use Ckeditor 5 in Laravel 9 Vite with Tailwind CSS

Laravel 9 Simple Image Upload in Ckeditor 5 Example

Laravel 9 Flash Message Timeout and Hide Message Example

Install & Setup Markdown Editor in Laravel 9

Nuxt 3 Data Fetching Using Laravel 9 Api Example

Laravel 9 Image Upload with Preview using Tailwind CSS & Alpine JS

Laravel 9 with Tailwind CSS Form Validation Example

Laravel 9 Backend Api Connect with Vue 3 Using Axios Example

Laravel 9 Authentication with Next js Example

Laravel 9 Sanctum Authentication with Nuxt JS Example

Laravel 9 Simple Search with Pagination Example

Laravel 9 Install Setup TALL(Tailwind, Alpinejs, Livewire) Admin Panel

How to Fix and Clean Code Style in laravel 9

Laravel 9 Image File Upload Example

3 Way to Create Slug in Laravel 9 without Package

How to Add Dark Mode in Laravel 9 with Tailwind CSS