Defining Your Own Helper Classes in Laravel 4
Sep 9, 2013  

I'm starting with some fairly generic stuff, but with the intentions of referring back to it in the future. You're going to run in to some cases where you would like to use a custom Helper to accomplish a task. In Laravel 4, we can do this one of several ways, but the easiest way I found is to modify our app/start/global.php to include a custom directory on boot vs requiring each new helper individually.

The first step is to create a directory under the app folder. I named mine <code>classes, but you can name yours whatever you would like. So our directory structure should look like this app/classes. Next, we want to open our global.php file and find <code>ClassLoader::addDirectories(array( which should be at the very top. We're going to add our classes directory in to this array.

    app_path().'/classes', //we added this

Now we are going to create a class called Helpers.php in our classes directory.

class Helpers {
    public static function doMessage() {
        $message = 'Hello';
        return $message;

At some point during all of this we need to composer dump-autoload, but after that we can start using the methods we just built. To use, just call <code>Helpers::doMessage(); Notice, how our call resembles the name of our class Helpers. You can use these methods in your controller or blade templates. Check out this answer on Stack Overflow for more info and use with Laravel 3.