PHPStorm auto-complete not working with Laravel 5
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
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 inconfig/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
Two possible fixes for that:
- Make your models extend the \Eloquent facade instead of Illuminate\Database\Eloquent\Model.
- 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)
In addition to the IDE Helper, you must enable the Laravel Plugin per-project in PHPStorm.
- Open preferences.
- Navigate to
Laravel Plugin
- Check
Enable plugin for this project