PHPStorm 自动完成功能不适用于 Laravel 5

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30744564/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 11:45:03  来源:igfitidea点击:

PHPStorm auto-complete not working with Laravel 5

phplaravelphpstorm

提问by Andrei

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

我正在使用 PHP Storm v8.0.3 和最新版本的 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.

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

enter image description here

在此处输入图片说明

I have included it in the providersarray as either

我已将它包含在providers数组中

'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider'

'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider'

or

或者

Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider:class

Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider:class

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

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

I have also installed the Laravel plugin.

我还安装了 Laravel 插件。

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.

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

回答by Meir Cohen

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.
  1. 让你的模型扩展 \Eloquent 外观而不是 Illuminate\Database\Eloquent\Model。
  2. 如果你更喜欢继续使用“模型”外观,你可以在 config/app.php 中创建自己的别名,然后在额外的 config/ide-helper.php 中将“eloquent”更改为“model”。这将让 ide-helper 包含来自 Illuminate\Database\Eloquent\Builder 和 Illuminate\Database\Query\Builder 的所有方法,这是缺失的方法实际存在的地方。

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

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

回答by Tia

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.

这篇文章让我开始使用 PHPStorm 2016.1.2,但它已经大了一年,所以我想它可以与旧版本一起使用。

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

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:

可能缺少的唯一细节,我在插件 GitHub 链接上找到了它们:

After updating composer, add the service provider to the providersarray in config/app.phpBarryvdh\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

更新composer后,将服务提供者添加到providers数组中config/app.phpBarryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,

php artisan ide-helper:generate

注意:bootstrap/compiled.php 必须先清除,所以在生成之前运行 php artisan clear-compiled(然后运行 ​​php artisan optimize)。

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

回答by Ian

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

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

  1. Open preferences.
  2. Navigate to Laravel Plugin
  3. Check Enable plugin for this project
  1. 打开首选项。
  2. 导航 Laravel Plugin
  3. 查看 Enable plugin for this project

回答by Fadi

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

我尝试了所有的答案,但是在我doctrine/dbal为模型包含自动 phpDocs之后,代码自动完成开始工作,因为模型的自动 phpDocs 添加了@mixin \Eloquent,这可以解决问题等等;)

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