Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPStorm auto-complete not working with Laravel 5 [duplicate]

I'm using PHP Storm v8.0.3 with the latest version of Laravel.

I'm having trouble making the autocomplete work.

enter image description here

As you can see in the image above.


I have installed barryvdh ide-helper, following the readme he provides on git. I haven't received any errors during its installation.

enter image description here

I have included it in the providers array as either

'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider'

or

Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider:class

It didn't make any difference(as far as I can tell).

I have also installed the Laravel plugin.

Again, no difference, still no auto-complete.

enter image description here

I tried dumping the config file which resulted in:

array:27 [▼
 ...
  22 => "Illuminate\View\ViewServiceProvider"
  23 => "Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider"
  24 => "App\Providers\AppServiceProvider"
 ...
]

I'm really stuck on this one. I have no idea what could be wrong. Any nudging in the right direction is greatly appreciated.

like image 254
Andrei Avatar asked Jun 09 '15 23:06

Andrei


4 Answers

Two possible fixes for that:

  1. Make your models extend the \Eloquent facade instead of Illuminate\Database\Eloquent\Model.
  2. If you prefer to keep using the "Model" facade, you can make your own alias in config/app.php, then change "eloquent" to "model" in the config/ide-helper.php under extra. This will let ide-helper include all the methods from Illuminate\Database\Eloquent\Builder and Illuminate\Database\Query\Builder which is where the missing methods actually live.

(Source: https://laracasts.com/discuss/channels/general-discussion/phpstorm-thinks-modelwhere-doesnt-exist-on-model-l5/replies/37661)

like image 200
Meir Cohen Avatar answered Nov 08 '22 08:11

Meir Cohen


This article got me going with PHPStorm 2016.1.2, but it is one year older so I suppose it would work with older version.

https://blog.jetbrains.com/phpstorm/2015/01/laravel-development-using-phpstorm/

The only details that are probably missing, I found them on the plugin GitHub link:

After updating composer, add the service provider to the providers array in config/app.php Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,

php artisan ide-helper:generate

Note: bootstrap/compiled.php has to be cleared first, so run php artisan clear-compiled before generating (and php artisan optimize after).

Source: https://github.com/barryvdh/laravel-ide-helper

like image 21
Tia Avatar answered Nov 08 '22 08:11

Tia


i tried all the Answers, but after i include doctrine/dbal for automatic phpDocs for models, the code autocomplete start to work because the automatic phpDocs for models added the @mixin \Eloquent and this do the trick and more ;)

steps:

https://github.com/barryvdh/laravel-ide-helper

Require this package with composer using the following command:
composer require --dev barryvdh/laravel-ide-helper

After updating composer, add the service provider to the providers array in config/app.php
Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,

php artisan clear-compiled
php artisan ide-helper:generate
php artisan optimize

You can configure your composer.json to do this after each commit:

"scripts":{
    "post-update-cmd": [
        "Illuminate\\Foundation\\ComposerScripts::postUpdate",
        "php artisan ide-helper:generate",
        "php artisan ide-helper:meta",
        "php artisan optimize"
    ]
},


composer require doctrine/dbal

php artisan ide-helper:models
like image 26
Fadi Avatar answered Nov 08 '22 10:11

Fadi


In addition to the IDE Helper, you must enable the Laravel Plugin per-project in PHPStorm.

  1. Open preferences.
  2. Navigate to Laravel Plugin
  3. Check Enable plugin for this project
like image 3
Ian Avatar answered Nov 08 '22 09:11

Ian