Code Styling in Laravel: 11 Common Mistakes

For fixing code styling mistakes, there's a great tool called Laravel Pint. In this article, I will list one of the most typical fixes it makes, with before/after examples.


1. Unused Imports

Unused imports are one of the most common code style issues in code. This can be caused by copying and pasting some code or simply by refactoring some classes. It usually looks like this:

While my editor marked them as unused - that might not be the case for your editor. That's why Pint has a rule about it:

https://github.com/laravel/pint/blob/main/resources/presets/laravel.php

'no_unused_imports' => true,

And once you run /vendor/bin/pint fix it will remove all unused imports:


2. Function Visibility

Functions in PHP should have their visibility defined even if it's public by default. This is a...

The full tutorial [7 mins, 1226 words] is only for Premium Members

Login Or Become a Premium Member for $129/year or $29/month
What else you will get:
  • 68 courses (1183 lessons, total 43 h 18 min)
  • 90 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord

Recent New Courses