安裝 laravel-ide-helper

簡(jiǎn)介

安裝

  • composer require barryvdh/laravel-ide-helper

注冊(cè)服務(wù)提供者

  • 在config/app.php中providers下添加代碼
'providers' => [
    Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class
]

自動(dòng)運(yùn)行 generate

  • 想在依賴包更新是自動(dòng)更新注釋,可以在 composer.json 文件中做如下配置
"scripts":{
    "post-update-cmd": [
        "Illuminate\\Foundation\\ComposerScripts::postUpdate",
        "php artisan ide-helper:generate",
        "php artisan ide-helper:meta"
    ]
}

生成配置文件

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

  • 然后在生成的config/ide-helper.php中第28行將 ‘include_fluent’ => false, 修改為 ‘include_fluent’ => true,
  • 建議將 ‘include_helpers’ => false,’ (66行)改為true 作用:讓Laravel Ide Helper幫我們建立helper function注解
  • 當(dāng)你的model目錄修改時(shí)在 配置文件中82行將 'app’修改為你的model所在目錄

使用

php artisan ide-helper:generate - 為 Facades 生成注釋
php artisan ide-helper:models - 為數(shù)據(jù)模型生成注釋
php artisan ide-helper:meta - 生成 PhpStorm Meta file

自動(dòng)為 Laravel 的 Facades 生成注釋

php artisan ide-helper:generate

自動(dòng)為模型生成注釋

//輸入 yes 則會(huì)直接在模型文件中寫入注釋,否則會(huì)生「_ide_helper_models.php」文件
php artisan ide-helper:models

生成 .phpStorm.meta.php

可以生成一個(gè) PhpStorm meta 文件去支持工廠模式。對(duì)于 Laravel, 這意味著我們可以讓 PhpStorm 理解我們從 IoC 容器中解決了什么類型的對(duì)象
php artisan ide-helper:meta

結(jié)束

  • 感謝閱讀
?著作權(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),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

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