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.
I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.