The most powerful Laravel/PHP tool you're not using yet

Eduard Lupacescu

almost 5 years ago

The most powerful Laravel/PHP tool you're not using yet

I know we all don’t have enough time! Well at least in the PHP world we finally have a solution that will save us a lot of time in the daily routine!

I would like to mention that I’m always impressed, inspired and support people who innovate things that allow the others to improve their workflows. These remember me of the parallel operations from a quantum processor. A few weeks ago, Marcel Pociot presented to the community the best PHP realtime interpreter I’ve ever seen — Tinkerwell. He has a built-in Laravel app, and you can open easily your project over it.

How can it help you outside of Laravel?

Simply by playing around with PHP, you get a really good experience, as we already know — the single way to learn a language is by typing and again typing. This IDE helps me to learn a lot faster PHP — considering we have all Laravel helpers as dd this is even faster. Thing of a cool real time console that shows you code outputs per line as you type.

null

Ok, but how can it help me?

We can talk about this a lot, because it can change your mind, it opens a lot of possibilities you didn’t have before. As programmers we tend to be very lazy. We are lazy to run the code again and again by using a command and test the best way for a specific implementation. Sometimes because it's hard to run or debug a specific piece of code, other times because it takes time. Having a tool like this, even the laziest programmer will have the pleasure to work around and figure out the best, the most performant solution because code can be isolated and run at the lowest level.

This IDE allows you to code under a specific namespace in your Laravel project, so you can write a service right away

null

A real world scenario

I had an xls parser in one of the projects, it was working pretty well and was in place but suddenly a bug appeared. With Tinkerwell the debugging was a pleasure, imagine you have all the control under your code and interpretation. Before I had to go into POSTMAN and run a POST request (or run a Laravel command) to try and debug/reproduce the bug, which trust me, is a pain. This is what I had for:

null

The bug was coming from an application build with Laravel Nova. After updating a customer, he lost his relations to other entities (as order or address)! Telescope (logging tool) didn’t suggest anything specific. I checked the relation first

null

and noticed an empty collection:
 

null

Couple of minutes later, I’ve realized that the client has a field (client_id) which is mutated by nova (via withMeta method) for each request (this is an on the fly mutation, and not a persistent one).

null

null

That’s it. Bug found! By moving this randomly generated id on the creation event from the nova fields to the boot event, the issue was solved. Hooray!

null

This is just the tip of the iceberg. Definitely there are a lot of other use cases where I use it in my daily routine. Although this sounds lame — I truly don’t understand how I lived before without this tool. A lot of repetitive actions to trigger and debug certain code were simply replaced with Tinkerwell. At Binar Code we've built a few automation projects which require a lot of triggers and attention to details. Sometimes certain pieces of code require complex flows, automated jobs and a lot of actions in order to be reached or triggered. By doing this manually, you end up spending quite a lot of time reproducing a complex flow to trigger some code rather than writing and improving that code.

How Tinker can help you learning PHP faster ?

Let’s say you’re learning new Laravel 6 features, and usually, we type what Jeffrey Way types in the lesson. The idea is that using Tinkerwell this process is a lot faster as you can see the outputs in real time. I'm pretty sure that in the next lessons even Jeffrey will use Tinkerwell.

null

Bonus Tip:

As a daily routine, I noted that I often open Tinkerwell from the terminal (from PHPStorm built-in). I just have to type tinker .

For doing that, just use this gist. I’m using zsh terminal so I had to add it here as a .py file in my ~/.zsh/ directory, and alias it in your bash_profile or .zshrc file as: 

alias tinker= “absolute_path_to_py_file/tinkerwell.py"

Thanks to people like Marcel Pociot the community is evolving and people can write meaningful code faster than ever.

Comments

Explore more articles