DEV Community

Cover image for How to Fix and Clean Code Style in laravel 9
saim
saim

Posted on • Originally published at larainfo.com

3

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
Enter fullscreen mode Exit fullscreen mode

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'));
}
Enter fullscreen mode Exit fullscreen mode

After run ./vendor/bin/pint

./vendor/bin/pint
Enter fullscreen mode Exit fullscreen mode

laravel clean code

After run pint

public function index()
{
    $categories = Category::latest()->paginate(10);

    return view('category.index', compact('categories'));
}
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

Image of Docusign

Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

Billboard image

Deploy and scale your apps on AWS and GCP with a world class developer experience

Coherence makes it easy to set up and maintain cloud infrastructure. Harness the extensibility, compliance and cost efficiency of the cloud.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay