Custom Helper functions in Laravel

In this post, we gonna create custom functions and load it in the Laravel project. These functions can be accessible all over the project. Loading custom helper functions in Laravel is pretty straightforward. Let’s follow the below steps,

First, create a file called TextHelper.php the filename can be anything, and place your custom functions in the file. Depending on your preference, you can organize the location of your helper file(s) however you want, however, we gonna create a folder called Helpers in the app folder, inside this folder we will place helper(s).

Now you have to load this helper file so that the helper function will be available in the project. So in order to load the helper file, update your composer.json file autoload section as shown below.

We just added a files key to autoload object and files key holds an array of file paths. Now you need to dump the autoloader with below compose command

Now you can use the the_excerpt() function in your laravel project.

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

0 0 vote
Article Rating
Notify of
Inline Feedbacks
View all comments Protection Status
Would love your thoughts, please comment.x