- 在项目目录下执行如下命令
composer require 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
这时会出现询问:
1
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 都会更新,如下代码
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan ide-helper:generate",
"php artisan optimize"
]
让Command Line Tool Console
控制台支持artisan
命令
选择settings
里的Tools
里的Command Line Tool Support
,点击右上角的加号
Image 3.png
点击ok
Image 4.png
设置完成后,打开Command Line Tool Console
控制台,在里面输入如下内容(可以通过输入contr..来选择命令),如果在项目的app
目录里的Http
目录里的Controllers
里有新建的TestController
文件,说明配置是成功的