在項(xiàng)目目錄下執(zhí)行如下命令
composer require barryvdh/laravel-ide-helper
//如果只想在開發(fā)環(huán)境上使用,請(qǐng)加上--dev
composer require --dev barryvdh/laravel-ide-helper
在config/app.php里面的providers 里面添加如下代碼:(5.5以下版本需要加)
Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class, // ide helper
配置好數(shù)據(jù)庫連接,然后在項(xiàng)目目錄下執(zhí)行如下命令:
php artisan clear-compiled
php artisan ide-helper:generate
php artisan optimize
允許應(yīng)用程序在非生產(chǎn)環(huán)境中加載Laravel IDE Helper
在app/Providers/AppServiceProvider.php文件中的register()方法中添加下面的代碼:
//允許應(yīng)用程序在非生產(chǎn)環(huán)境中加載Laravel IDE Helper
if ($this->app->environment() !== 'production') {
$this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
}
使用publish命令將軟件包配置復(fù)制到本地配置:
php artisan vendor:publish --provider="Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider" --tag=config
修改配置文件ide-helper.php(自動(dòng)為鏈?zhǔn)讲僮髯⑨專?
include_fluent' => true
為 Facades 生成注釋
必須首先清除bootstrap/compiled.php,運(yùn)行以下命令進(jìn)行清除:
php artisan clear-compiled
為 Facades 生成注釋:
php artisan ide-helper:generate
為模型生成注釋
php artisan ide-helper:models
這時(shí)會(huì)出現(xiàn)詢問:
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 則會(huì)直接在模型文件中寫入注釋,否則會(huì)生成「_ide_helper_models.php」文件。建議選擇 yes,這樣在跟蹤文件的時(shí)候不會(huì)跳轉(zhuǎn)到「_ide_helper_models.php」文件,不過這么做最好對(duì)模型文件做個(gè)備份,至少在生成注釋之前用 git 控制一下版本,以防萬一。
提示: 為模型生成字段信息必須在數(shù)據(jù)庫中存在相應(yīng)的數(shù)據(jù)表,不要生成 migration 還沒運(yùn)行 migrate 的時(shí)候就生成注釋,這樣是得不到字段信息的。
還可以在composer.json 的 post-update-cmd 中加入命令保證helper 在每次commit 都會(huì)更新,如下代碼
"scripts":{
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
"php artisan ide-helper:generate",
"php artisan ide-helper:meta"
]
},
由于擴(kuò)展會(huì)生成相應(yīng)的文件,可能只針對(duì)當(dāng)前開發(fā)者有用,所以需要添加到.gitignore中
.idea
_ide_helper.php
_ide_helper_models.php
.phpstorm.meta.php
轉(zhuǎn)載于:
https://blog.csdn.net/qq_39586877/article/details/96483175,
https://www.cnblogs.com/jkko123/p/10677785.html