久久久久久久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)
主站蜘蛛池模板: 日本在线免费视频 | 亚洲视频在线免费观看 | 日韩精品一区二区三区在线 | 刘亦菲国产毛片bd | 久久久av中文字幕 | 天天爽夜夜爽精品视频婷婷 | 欧美1—12sexvideos | 免费在线成人 | 国产一区二区毛片 | 国产精品1区2区3区 欧美 中文字幕 | 99精品视频一区二区三区 | 日韩欧美亚洲 | 国产精品久久精品 | 日韩成人免费视频 | 亚洲不卡在线视频 | 黄色一级大片在线免费看产 | 秋霞性生活| 成人做爰www免费看视频网站 | 精品久久久久久国产 | 久久国产精品-国产精品 | 久在线精品视频 | 国产日韩欧美一区二区在线播放 | 日韩在线视频一区二区三区 | 欧美中文字幕一区 | 国产特级毛片 | 久久久久久国产 | 亚洲欧美一区二区三区情侣bbw | av网站免费在线观看 | 欧美一区二区大片 | 国产精品一区二区三区四区 | 精品视频一区二区三区在线观看 | 天天综合久久 | 日韩电影免费在线观看中文字幕 | 婷婷丁香综合网 | 国产不卡一区 | 日韩成人精品在线观看 | 欧美日韩亚洲国产 | 欧美一区二区精品 | 久久在线 | 理论片免费在线观看 | 成人久久久久 |