Boost Your Productivity in Laravel With Advanced PhpStorm Setup

Dmitry Khorev
4 min readJun 5, 2022

--

Write clean code more efficiently

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.

A list of things I cover in this series:

  1. What makes PhpStorm your perfect IDE for productivity?
  2. Minimum viable local environment setup for Laravel development with PHP, Node.js, MySQL, and Redis.
  3. Recommended plugins for PhpStorm. Turn your IDE into a powerhouse for Laravel development.
  4. Must have composer packages for Laravel developers.
  5. Setting up developer tools and packages within PhpStorm for Laravel.

To follow along I recommend either a Linux machine or a virtual machine with fresh Ubuntu installed (Virtualbox recommended).

VM has the advantage that your work environment is isolated from the personal environment, and can be easily snapshotted and rolled back in case of any trouble.

In this part of my series, I will try and demo some powers of having a properly configured IDE when it comes to Laravel development.

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.

Overview of available inspections for PHP and other tools
Overview of available inspections for PHP and other tools

Examples of inspections you are going to have

Null pointer inspection
Null pointer inspection
Ternary operator reduction inspection
Ternary operator reduction inspection
If/else reduction inspection with two returns
If/else reduction inspection with two returns

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.

Auto-formatting settings
Auto-formatting settings
Auto-formatting and optimizing imports in PHP

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.

Auto-formatting and optimizing imports Node.js
Auto-formatting and optimizing imports Node.js

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).

Search Everywhere tool in action

Configurable common file and method templates

PHP class and test class creation in action
PHP class and test class creation in action
Unit test method creation in action
Unit test method creation in action

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.

Model properties auto-completion in code and in model factories when unit testing

Git integration

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

Git integration demo
Git integration demo

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.

--

--

Dmitry Khorev

Sharing my experience in software engineering (NestJS, Laravel, System Design, DevOps)