PHPStorm 自动完成不适用于 Laravel 5

PHPStorm auto-complete not working with Laravel 5

我正在使用 PHP Storm v8.0.3 和最新版本 Laravel。

我在使用自动完成功能时遇到问题。

如上图所示。


我已经按照他在 git 上提供的自述文件安装了 barryvdh ide-helper。我在安装过程中没有收到任何错误。

我已将其包含在 providers 数组中,作为

'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider'

Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider:class

没有任何区别(据我所知)。

我还安装了 Laravel 插件。

同样,没有区别,仍然没有自动完成。

我尝试转储导致以下结果的配置文件:

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

我真的被这个问题困住了。我不知道可能出了什么问题。非常感谢任何朝着正确方向的推动。

两个可能的修复方法:

  1. 使您的模型扩展 \Eloquent 外观而不是 Illuminate\Database\Eloquent\Model。
  2. 如果您希望继续使用 "Model"门面,可以在config/app.php中制作自己的别名, 然后把config/ide-helper.php下的"eloquent"改成"model" 额外的。这将使 ide-helper 包含来自 Illuminate\Database\Eloquent\Builder 和 Illuminate\Database\Query\Builder 这是缺少方法的地方 实际生活

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

除了 IDE Helper,您还必须在 PHPStorm 中为每个项目启用 Laravel 插件。

  1. 打开首选项。
  2. 导航到 Laravel Plugin
  3. 勾选Enable plugin for this project

这篇文章让我开始使用 PHPStorm 2016.1.2,但它比旧版本早一年,所以我想它适用于旧版本。

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

唯一可能遗漏的细节,我在插件上找到了 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

我尝试了所有的答案,但是在我为模型的自动 phpDocs 添加了 doctrine/dbal 之后,代码自动完成开始工作,因为模型的自动 phpDocs 添加了 @mixin \Eloquent,这就成功了还有更多 ;)

步骤:

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