Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

265
Views
How can I provide hints to PhpStorm to find my Laravel custom query builder methods?

I'm using custom query builders in Laravel like this:

class MyModel extends Model {
 public function newEloquentBuilder($query): MyModelQueryBuilder
    {
        return new MyModelQueryBuilder($query);
    }
}
class MyModelQueryBuilder extends Illuminate\Database\Eloquent\Builder {
  // various query methods...
}

Because of Laravel's so-called Facades and use of magic methods, PhpStorm cannot find references to the methods in my custom query builder.

I use the barryvdh/laravel-ide-helper package to generate hints for my Models, so their methods are findable and hintable. How can I do the same thing in an easy, maintainable way for my query builder classes?

For example, I'd like to be able to press Command-B while on a query builder method, and get the list of users of that method, for example, as I can with other fully cross-referenced classes.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You'll need to add the class methods to the model using the unofficial @mixin PHPDoc directive. PhpStorm has had support for it for a few years now. A trait is probably the easiest way to do this on multiple models:

/**
 * @mixin MyModelQueryBuilder
 */

trait HasCustomBuilder {

    public function newEloquentBuilder($query): MyModelQueryBuilder
    {
        return new MyModelQueryBuilder($query);
    }
}
class MyModel extends Model {
    use HasCustomBuilder;
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!