Laravel 8 autocompletion not working for Eloquent ::find and ::where

PHPStorm version: 2021.2

For some reason my workspace for a Laravel 8 project doesn't have the autocompletion working for basic Eloquent builders. I'm trying to use

User::find()
User::where()

These 2 for example are not being autocompleted.

I've read while researching that @mixin Eloquent should have fixed it, but unfortunately it doesn't work for me. I did install barryvdh/laravel-ide-helper

And ran these commands

sail artisan clear-compiled
sail artisan ide-helper:generate
sail artisan ide-helper:meta
sail artisan ide-helper:models

When prompted for models, I picked yes. I have a project running on Laravel 7 and it seems to work fine

1
6 comments

Hi there,

Possibly unrelated but... What is Eloquent in "@mixin \Eloquent" line?

From what I know \Eloquent resolves to "class Eloquent extends \Illuminate\Database\Eloquent\Model" (declared in the _ide_helper.php that Laravel IDE Helper generates).

Having such a line there on your screenshot dos not make sense to me sine User is already a child class of Eloquent\Model class... Must be some issue in Laravel IDE Helper code...

 

Anyway: I normally just add these to eloquent model classes (you may leave only the needed class). May not be the best solution -- not as good as listing specific return types for each method.. but it's much less work and works good enough for my needs.

* @mixin \Illuminate\Database\Eloquent\Builder
* @mixin \Illuminate\Database\Query\Builder

or like this (which is better if you need to use such class later in the code):

use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder as QueryBuilder;

/**
* @mixin EloquentBuilder
* @mixin QueryBuilder
*/
class User extends Authenticatable

 

These screenshots show 2 signatures: one from each mixin class.

The above is shown when I manually type the method name. If it needs to be offered by Code Completion popup, then you may need to invoke it twice (Ctrl+Space 2 times; Ctrl+Space is the shortcut for "Code | Code Completion | Basic")

1

Hello Andriy Bazanov Thank you for the reply.

That mixin Eloquent line is added by the ide-helper, I'm also not entirely sure what is the purpose. I do also get the methods when I type Cmd + Space. But it's weird, I've used Laravel + PHPStorm in the past, and I don't remember I needed to press Cmd + Space. Also the Laravel 7 project doesn't require me to invoke the Cmd + Space. This is frustrating me since I'm always used to seeing the popup for those two methods.

0

Checked that on  "laravel/framework": "^8.65" + "barryvdh/laravel-ide-helper": "^2.10" and it worked fine here:

But that's a fresh project. Please run File > Invalidate Caches ... > turn on Clear file system cache and Local History and Clear downloaded shared indexes, then hit Invalidate and Restart and check the issue after that. 

0

I have the same problem with Laravel v8.75. I tested with intellij version: 2021.2 and 2021.3.

0

Are you able to share your project somehow?

0

I solved this issue by going to the Model.php class and removed all mixins except @mixin \Eloquent

 

1

Please sign in to leave a comment.