In this episode, we talk about improving your IDE experience when working with Laravel's QueryBuilder. We start by showing why calling the QueryBuilder explicitly (instead of chaining methods straight off the model) can help your IDE—like VSCode or PhpStorm—understand what methods are available, letting you click through and inspect their definitions more easily.
There's a quick demo where we define a variable by querying for a post with a certain slug. At first, when chaining methods directly from the model, our IDE can't follow where these methods are coming from because of some PHP magic happening in Laravel. But if we use the QueryBuilder
method, our IDE recognizes the builder instance, and all those nifty jump-to-definition and code inspection features start working.
Finally, we mention that while some IDEs or plugins may add extra support for Laravel, using the QueryBuilder directly is a quick, universal way to help your IDE help you—making it way easier to read and understand complex queries as your app grows.