LARAVEL

How To Create Custom Helper Functions in Laravel 5


Laravel 5 comes with many inbuilt helper functions right out of the box. The challenge we have as developers is that we are never satisfied with the status quo :) , We often crave for more.

It’s a very good thing to be an Oliver twist. Several situations may arise to make you want to have your own helper functions, one of which is having repeated blocks of code all over your views or any part of your app.

Now, let’s go through a very simple way of creating custom helper functions in Laravel 5.

1. Create a file called helpers.php in your App/Http Directory.

2. Open your composer.json file and add this

3. Run

Example

That’s one of the custom helper functions I use in almost all my Laravel projects and that resides in helpers.php.

So you can write as many simple functions in helpers.php and use it in any part of your app.

Please let me know if you have any questions in the comment section.

PROSPER OTEMUYIWA

About PROSPER OTEMUYIWA

Food Ninja, Code Slinger, Technical Trainer, Accidental Writer, Open Source Advocate and Developer Evangelist.