久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何在ServiceProvider中自動注冊helpers類?

How to automatically register helpers class in ServiceProvider?(如何在ServiceProvider中自動注冊helpers類?)
本文介紹了如何在ServiceProvider中自動注冊helpers類?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在從事 Laravel 5.1 項目并開發了很多幫助程序.

I am working on Laravel 5.1 project and have developed a lot of helpers.

有沒有辦法在ServiceProivder中自動注冊helpers類,而不是手動添加?

Is there any way to automatically register helpers class in ServiceProivder in stead of adding them manually?

推薦答案

我一直在努力,最終通過將不同的謎題放在一起解決了這個問題:

I have worked on it and I finally fixed it by putting different puzzles together ending with this solution:

對于 Laravel 5:

步驟 1. 創建文件夾 app/Helpers

第 2 步.app/Providers 文件夾中,使用以下工匠命令創建提供程序 HelpersServiceProvider.php:

Step 2. In app/Providers folder, create provider HelpersServiceProvider.php using following artisan command:

php artisan make:provider HelpersServiceProvider

第 3 步.HelpersServiceProvider.php 文件中,我們在 register 函數中創建一個 foreach 循環 來獲取所有 helpers 類,如下所示:

Step 3. In HelpersServiceProvider.php file, we make a foreach loop inside register function to fetch all helpers classes like this:

public function register()
{
    foreach (glob(app_path() . '/Helpers/*.php') as $helpersfilename)
    {
        require_once($helpersfilename);
    }
}

第 4 步.config/app.php 中添加以下行

/*
* Application Service Providers added by developer...
*/
AppProvidersHelpersServiceProvider::class,

就是這樣,這里的解決方案已經過測試,適用于所有版本的 Laravel 5.x.現在你可以在 helpers 文件夾中添加無限的助手,它們會自動添加到系統中.

That is it, the solution here is tested and works on all versions of Laravel 5.x. Now you can add unlimited helpers in helpers folder, they will be automatically added to the system.

Laravel 4 尚未測試,但如果有人這樣做,請為 Laravel 4 添加/編輯此內容.

Laravel 4 is not tested yet, but if some body do it, please add/edit this for Laravel 4.

這篇關于如何在ServiceProvider中自動注冊helpers類?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Magento products by categories(按類別劃分的 Magento 產品)
Resource interpreted as image but transferred with MIME type text/html - Magento(資源被解釋為圖像但使用 MIME 類型 text/html 傳輸 - Magento)
Is there an event for customer account registration in Magento?(Magento 中是否有客戶帳戶注冊事件?)
Magento addFieldToFilter: Two fields, match as OR, not AND(Magento addFieldToFilter:兩個字段,匹配為 OR,而不是 AND)
quot;Error 404 Not Foundquot; in Magento Admin Login Page(“未找到錯誤 404在 Magento 管理員登錄頁面)
Get Order Increment Id in Magento(在 Magento 中獲取訂單增量 ID)
主站蜘蛛池模板: 久久久午夜精品 | 亚洲精品乱码久久久久久蜜桃91 | 日韩免费看 | 亚洲精品网站在线观看 | 久久久久久一区二区 | 国产午夜在线 | 亚洲一区成人 | 亚洲毛片网 | 精品国产99久久久久久宅男i | 国产免费一区二区三区最新不卡 | 国产伊人网 | 看黄网站在线观看 | 97视频在线免费观看 | 日本伊人网 | 国产精品成人免费一区久久羞羞 | 国产精品三 | 亚洲一区二区三区四区在线 | 好色婷婷| 亚洲最新av | 国产精品久久久久久久午夜 | 91精品国产乱码久久久久 | 一区二区国产视频 | 激情综合婷婷 | 亚洲黄色在线 | 欧美精品99| 欧美日韩中文字幕在线 | 秋霞午夜鲁丝一区二区老狼 | 日韩三级精品 | 国产一区免费视频 | 欧美精品综合 | 国产成人亚洲精品自产在线 | 国产精品久久久久永久免费看 | 国产三级成人 | 欧美视频在线观看免费 | 久久精品国产亚洲 | 麻豆视频一区二区 | 四虎影院www| 欧美又大粗又爽又黄大片视频 | 一级黄片毛片 | 欧美成人精品一区二区三区 | 国产日韩久久 |