Skip to content

Instantly share code, notes, and snippets.

@setkyar
Created January 23, 2015 07:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save setkyar/7d14b3d8e963d8d146d4 to your computer and use it in GitHub Desktop.
Save setkyar/7d14b3d8e963d8d146d4 to your computer and use it in GitHub Desktop.
Laravel 4 Helper Class Function
//Create New Folder Call MyClass on `app/` directory
Add new line on `/app/start/global.php`
ClassLoader::addDirectories(array(
app_path().'/commands',
app_path().'/controllers',
app_path().'/models',
app_path().'/database/seeds',
app_path().'/MyClass', // This line is the one we need to add
));
Create a file in `app/MyClass/Helper.php` and add such as like
<?php namespace Helpers;
class Helper {
public static function helloWorld()
{
return 'Hello World';
}
}
All you would need to do is call `Helpers\Helper::helloWorld();`
You could also **alias** this helper class in your `/app/config/app.php` file. Just add something like this to the end of the aliases array:
'Helper' => 'Helpers\Helper'
@setkyar
Copy link
Author

setkyar commented Jan 23, 2015

See more on SO

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment