Laravel 的phpstorm 插件 laravel-ide-helper

在項(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

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
禁止轉(zhuǎn)載,如需轉(zhuǎn)載請(qǐng)通過簡信或評(píng)論聯(lián)系作者。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容