I have worked on it and I finally fixed it by putting different puzzles together ending with this solution:
For Laravel 5:
Step 1. Created folder app/Helpers
Step 2. In app/Providers
folder, create provider HelpersServiceProvider.php
using following artisan command:
php artisan make:provider HelpersServiceProvider
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);
}
}
Step 4. In config/app.php
added following line
/*
* Application Service Providers added by developer...
*/
AppProvidersHelpersServiceProvider::class,
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 is not tested yet, but if some body do it, please add/edit this for Laravel 4.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…