[英]PhpStorm and Laravel autocompletion
I decided to use PhpStorm for my new Laravel project, so I thought I wanted some autocompletion.我决定在我的新 Laravel 项目中使用 PhpStorm,所以我想我想要一些自动完成功能。 I did read the guide from https://blog.jetbrains.com/phpstorm/2015/01/laravel-development-using-phpstorm/ and some of it works fine, but I got a problem.
我确实从https://blog.jetbrains.com/phpstorm/2015/01/laravel-development-using-phpstorm/阅读了指南,其中一些工作正常,但我遇到了问题。
I wanted to test my DB connection, so I just made a simple index()
function like this我想测试我的数据库连接,所以我做了一个像这样的简单
index()
函数
if(DB::connection()->getDatabaseName()) {
echo 'Connected to ' . DB::connection()->getDatabaseName();
}
Which works fine, but when I write DB
and press Tab I write \\DB::
instead of DB::
.这工作正常,但是当我写
DB
并按Tab我写\\DB::
而不是DB::
。 Then I include use Illuminate\\Support\\Facades\\DB;
然后我包括
use Illuminate\\Support\\Facades\\DB;
and DB::
works.和
DB::
作品。 But when I added the facade, the autocompletion isn't the same at all and it cant find the methods but they works.但是当我添加门面时,自动完成完全不一样,它找不到方法但它们有效。 It's really annoying.
这真的很烦人。
Someone else had this problem and is there a solution for it?其他人遇到了这个问题,有解决方案吗?
In PhpStorm, Settings => plugins在 PhpStorm 中,设置 => 插件
Then after add this package:然后在添加这个包之后:
composer require barryvdh/laravel-ide-helper
You can find more help on github for this package: https://github.com/barryvdh/laravel-ide-helper你可以在 github 上找到关于这个包的更多帮助: https : //github.com/barryvdh/laravel-ide-helper
First, install the Laravel plugin for PhpStorm, then install laravel-ide-helper
.首先,为 PhpStorm 安装 Laravel 插件,然后安装
laravel-ide-helper
。 After that, generate ide-helper
for your project)之后,为您的项目生成
ide-helper
)
php artisan ide-helper:generate
php artisan ide-helper:meta
For correct autocomplete model you must identify this model use (model namespace)
对于正确的自动完成模型,您必须确定此模型的
use (model namespace)
想通了:) 只需将 DB 连接到您的班级,问题就解决了。
use DB;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.