Laravel 的phpstorm 插件 laravel-ide

2022-04-23  本文已影响0人  dark68

在项目目录下执行如下命令

composer require barryvdh/laravel-ide-helper
//如果只想在开发环境上使用,请加上--dev
composer require --dev barryvdh/laravel-ide-helper

在config/app.php里面的providers 里面添加如下代码:(5.5以下版本需要加)

Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,       // ide helper

配置好数据库连接,然后在项目目录下执行如下命令:

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

允许应用程序在非生产环境中加载Laravel IDE Helper

在app/Providers/AppServiceProvider.php文件中的register()方法中添加下面的代码:

//允许应用程序在非生产环境中加载Laravel IDE Helper
if ($this->app->environment() !== 'production') {
   $this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
}

使用publish命令将软件包配置复制到本地配置:

php artisan vendor:publish --provider="Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider" --tag=config

修改配置文件ide-helper.php(自动为链式操作注释):

include_fluent' => true

为 Facades 生成注释

必须首先清除bootstrap/compiled.php,运行以下命令进行清除:

php artisan clear-compiled

为 Facades 生成注释:

php artisan ide-helper:generate

为模型生成注释

php artisan ide-helper:models

这时会出现询问:

Do you want to overwrite the existing model files? Choose no to write to _ide_helper_models.php instead? (Yes/No): (yes/no``) [no]:

输入 yes 则会直接在模型文件中写入注释,否则会生成「_ide_helper_models.php」文件。建议选择 yes,这样在跟踪文件的时候不会跳转到「_ide_helper_models.php」文件,不过这么做最好对模型文件做个备份,至少在生成注释之前用 git 控制一下版本,以防万一。
提示: 为模型生成字段信息必须在数据库中存在相应的数据表,不要生成 migration 还没运行 migrate 的时候就生成注释,这样是得不到字段信息的。

还可以在composer.json 的 post-update-cmd 中加入命令保证helper 在每次commit 都会更新,如下代码

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

由于扩展会生成相应的文件,可能只针对当前开发者有用,所以需要添加到.gitignore中

.idea
_ide_helper.php
_ide_helper_models.php
.phpstorm.meta.php

转载于:
https://blog.csdn.net/qq_39586877/article/details/96483175,
https://www.cnblogs.com/jkko123/p/10677785.html

上一篇 下一篇

猜你喜欢

热点阅读