Eloquent ORM Code Hinting in PhpStorm

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company
# Mastering Eloquent Hints: Getting Code Completion for Query Builders in PhpStorm As developers working within the Laravel ecosystem, productivity hinges on tooling. IDEs like PhpStorm are powerful assistants, but sometimes they struggle to fully map the dynamic nature of ORMs like Eloquent, leading to frustrating code hinting issues. This is a common pain point when dealing with fluent query builders. I've recently encountered this exact scenario: attempting to use methods on an Eloquent `Builder` object within PhpStorm yields warnings instead of helpful code completion for methods like `orderBy()`, `take()`, or `skip()`. While basic operations work fine, the deeper, more complex querying methods remain elusive. This post dives into why this happens and provides a robust solution for ensuring your IDE gives you the best possible experience when working with Eloquent in Laravel projects. ## The Eloquent Context: Builder vs. Model Methods To understand the problem, we must first understand what is being hinted. In the example provided, you have defined an Eloquent `Model`: ```php namespace Project\Models; use Illuminate\Database\Eloquent\Model; use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract; class User extends Model implements AuthenticatableContract, CanResetPasswordContract { } ``` When you write `User::query()`, you are invoking the static method on the model to get an instance of the **Query Builder**. This Query Builder object is what holds the fluent methods (like `orderBy`, `where`, `join`) that allow you to construct database queries. The issue arises because IDEs often rely on static analysis or generated files to understand class structure. While tools like Laravel IDE Helper are fantastic for hinting on model relationships and facades, they sometimes miss the dynamic method chaining capabilities inherent in the query builder itself unless explicitly configured. ## Why Standard Helpers Fall Short You mentioned using `laravel-ide-helper`, which is excellent for integrating Laravel facades and model definitions into PhpStorm's understanding of your project structure. However, its scope might be limited to static class methods or basic Model interactions. The Query Builder methods are dynamic—they depend on the context of the object returned by `::query()`. The lack of hints isn't a bug in Laravel itself; it’s often an integration gap between the IDE's static analysis engine and the specific runtime behavior of Eloquent's query chain. We need to ensure the IDE is properly aware of the full scope of the framework's dynamic features, much like understanding the core structure defined by frameworks like those found at [https://laravelcompany.com](https://laravelcompany.com). ## The Solution: Enhancing IDE Awareness Since there isn't a single magic setting that universally solves this across all IDEs and versions, the solution often involves ensuring your IDE has the most up-to-date framework context, or employing a more direct approach for advanced project scaffolding. ### 1. Verify IDE Plugin Status First, ensure you are using the latest version of PhpStorm. IDE updates frequently include better integrations with popular frameworks. Check if there are any specific plugins related to Laravel or PHP static analysis that might be missing or outdated. ### 2. Leverage Composer Autoloading and Project Structure Ensure your `composer.json` autoloading is perfectly configured, as this is the foundation upon which all IDE indexing relies. While less likely to fix a dynamic hinting issue, a clean setup prevents many underlying parsing errors. ### 3. The Best Practice: Using Native PHP Type Hinting (If Available) In some advanced scenarios, developers find that forcing stricter type definitions can help the IDE. Although Eloquent methods are often dynamically typed, ensuring all related classes are correctly imported and defined helps the static analyzer build a more accurate map of what is available in the scope. For complex ORM interactions, we must remember that code quality extends beyond simply writing functional code; it involves writing *maintain