I would like to create helper functions to avoid repeating code between views in Laravel 5:
view.blade.php
Foo Formated text: {{ fo
This is my HelpersProvider.php file:
helpers as $helper) {
$helper_path = app_path().'/Helpers/'.$helper.'.php';
if (\File::isFile($helper_path)) {
require_once $helper_path;
}
}
}
}
You should create a folder called Helpers
under the app
folder, then create file called whatever.php
inside and add the string whatever
inside the $helpers array.
Done!
I'm no longer using this option, I'm currently using composer to load static files like helpers.
You can add the helpers directly at:
...
"autoload": {
"files": [
"app/helpers/my_helper.php",
...
]
},
...