Its rich ecosystem makes Laravel Framework a great choice for PHP development. There are 15+ standalone extensions to the framework that solve common problems of big and complex apps.
Some of them are very specific, like Laravel Cashier, which provides an easy Stripe integration for your projects.
Some of them are useful to projects of any size and complexity, and some of them allow us to build performant and scaling apps. Those extensions I will describe in this part of the series.
I will start with absolute must-haves.
I believe developers of middle and senior levels should always use those in their process where you have at least one external data store and/or expose any sort of APIs.
Everything that happens in your applications will be recorded and displayed here. This is a useful tool for finding bottlenecks in your apps. If your API response is slow — is it a database problem or a compute problem? What logs did that job call created? What tasks have the scheduler run in the last 5 minutes? All sorts of information can be found here.
One hint: add the Telescope trim job right away, to keep debug tables smaller.
This requires Redis and your project to be a bit bigger than a starter template. Horizon adds asynchronous task processing to your Laravel application. This allows your API/web pages to respond faster while offloading heavy work to Horizon instances.
Must have for any async queues processing, for WebSockets integration in your apps.
Has a nice feature of metrics to spot slow-running async jobs.
Now, we’ll go over developer productivity addons for your Laravel projects.
This will create a helper file to resolve all of your model fields so PhpStorm is aware of them. This will create a helper description file for all of the magic Eloquent methods (resolving methods and auto-completion, parameters hints).
php artisan ide-helper:model --nowrite
php artisan ide-helper:meta
php artisan ide-helper:generate
Add to your .gitingore file
And some automation — add to your composer.json scripts
Every time you run composer i or composer update — your models are refreshed.
A static code analysis tool designed for Laravel projects (under the hood PhpStan is used, so effectively you get both).
Add to your composer.json scripts
"analyze": ["vendor/bin/phpstan analyse"]
Now running the composer analyze command will test your code for any problems.
This command can be run during CI/CD cycle to ensure code quality on a project with a distributed team.
Pro Tip: you can get PhpStorm to automatically analyze working files and show any errors. We’ll see how this can be configured in the next article.
These tools will help keep your code to a selected standard. When used in CI/CD will enforce code standards on a team of developers for a project.
Add to your composer.json scripts
"lint": ["vendor/bin/phpcs --parallel=8"], "lint-fix": ["vendor/bin/phpcbf --parallel=8"],
Now running the composer lint command will test your code for any code standard violations.
Running composer lint-fix will fix any errors that are possible to fix automatically.
Pro Tip: you can get PhpStorm to automatically analyze working files and show any code standard violations. We’ll see how this can be configured in the next article.
This package extends PHP_CodeSniffer with a few custom rules, that help keep code organized when the team uses different IDEs with different settings.
You will either have phpcs.xml in your project or can create one. Just add anything you prefer to that file.
This will clean up any unused imports from your files.
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses"> <properties> <property name="searchAnnotations" value="true"/> </properties> </rule>
Report useless variables in your code:
How many spaces do you want to see around anonymous function declarations?
<rule ref="SlevomatCodingStandard.Functions.ArrowFunctionDeclaration"> <properties> <property name="spacesCountAfterKeyword" value="0"/> <property name="spacesCountBeforeArrow" value="1"/> <property name="spacesCountAfterArrow" value="1"/> <property name="allowMultiLine" value="true"/> </properties> </rule>
And so on. The list of available inspections is really large.
composer lint and composer lint-fix commands will automatically apply newly added rules.
Notable mentions will help you solve common problems when growing your project.
A bonus — for deploying your apps. I see people trying very hard to deploy their simplest apps and MVPs on complex cloud infrastructures. But for starters, this simple service can take you very far…
Recommended for first-time deployments and MVPs, developers, or teams without dedicated DevOps roles. A much cheaper solution than AWS + Terraform, or any other kind of CI/CD automation.
Internally it works on pre-configured EC2 servers (or any servers you can provide), but it takes out of the way a lot of obstacles for people new to DevOps.
Hope this was helpful. Good luck and happy engineering!
Also published here.