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
1 2 3 4 5 |
"autoload": { "files": [ "app/Http/helpers.php" ] } |
3. Run
1 |
composer dumpautoload |
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.
- How to build your own Youtube – Part 10 - August 1, 2016
- How to build your own Youtube – Part 9 - July 25, 2016
- How to build your own Youtube – Part 8 - July 23, 2016
- How to build your own Youtube – Part 6 - July 6, 2016
- Introducing Laravel Password v1.0 - July 3, 2016
- How to build your own Youtube – Part 5 - June 28, 2016
- How to build your own Youtube – Part 4 - June 23, 2016
- How to build your own Youtube – Part 3 - June 15, 2016
- How to build your own Youtube – Part 2 - June 8, 2016
- How to build your own Youtube – Part 1 - June 1, 2016