How to Setup a Powerful PhpStorm Configuration to Improve Laravel Development

Written by dkhorev | Published 2022/09/03
Tech Story Tags: laravel | php | phpstorm | laravel-framework | programming | software-engineering | software-development | developer-productivity

TLDRPhpStorm is WebStorm + PHP so it provides the same utility as WebStorm for JavaScript development. It provides a list of inspections that will validate your code on the fly. It will use a combination of your own preferences + PHP Code Sniffer linter, a config that you can share with the team. It also provides a huge list of static code inspections. It is also possible to find bugs for you way before they even hit a Pull Request. The best tool (“Search Everywhere”) is one of the best tools to navigate your codebase when you do not recall exactly what the class is.via the TL;DR App

As software engineers, our job is mainly to think a lot and write code (as little as possible). Writing code can be tedious, especially with Laravel where in many places it relies on pure “magic”, for example, model magic properties and methods, DB builder’s fluent API, and DI for interfaces.

You can’t always rely on your memory of what fields or relations each model at your project has, say 6 months after you finished initial development. Without good insight from your IDE, you’d feel lost in your older classes. So in this article, I want to share how I set up my Laravel projects within the PhpStorm IDE that boost my productivity levels by a lot.

Not only that — having IDE find possible bugs for you way before they even hit a Pull Request is priceless. Having an IDE hint to you where your code can be simplified and/or refactored — is priceless.

By just having the right IDE setup — you can learn and grow, meanwhile producing quality code and software.

What makes PhpStorm your perfect IDE for productivity?

Huge list of static code inspections

It provides a list of inspections that will validate your code on the fly. This is the list of mistakes you are not going to make thanks to a great IDE. Extensible with plugins.

Examples of inspections you are going to have

Code auto-format and optimize imports

This is a really powerful tool, it will use a combination of your preferences + PHP Code Sniffer linter, a config that you can share with the team.

Node.js development is also not a problem. PhpStorm under the hood is WebStorm + PHP so it provides the same utility as WebStorm for JavaScript development. Prettier or ESLint config is not a problem.

Best IDE’s navigation tool (“Search Everywhere”)

Double Shift (Shift + Shift) — opens the “Search Everywhere” dialog, and type in the class or file name. Use Alt + Left/Right arrows to switch tabs to “Classes/Files/Symbols’’ to narrow the search. This is one of the best tools to navigate your codebase when you do not recall exactly what the class name is (or when you know exactly and go straight to the expected file).

Configurable common file and method templates

Laravel model/query integration use cases

Very nice thing to have for bigger projects. Automatic model properties discovery and hints while typing them in various array input/output situations.

Git integration

Git blame, visual interface for — commit and push, switching branches, merge conflict resolving, etc.

This concludes the first part of my series for Laravel productivity with PhpStorm. In my next article, I will share the minimum viable local environment setup for Laravel development with PHP, Node.js, MySQL, and Redis.


Also published here.


Written by dkhorev | Sharing my ideas on software development (NestJS, Laravel, System Design, DevOps for backend engineers)
Published by HackerNoon on 2022/09/03