How to create custom helper functions in Laravel | Laravel Point

 

How to create custom helper functions in Laravel

In Laravel, you can create custom helper functions in the following way:

  1. Create a new PHP file in the app/helpers.php directory.
  2. Write the function(s) you need in the file.
  3. Add the following line of code in the composer.json file to autoload the helpers file:
"autoload": {
    "files": [
        "app/helpers.php"
    ]
}    
 

    4. Run composer dump-autoload to update the autoloader.

Now you can use the custom helper functions anywhere in your Laravel application by simply calling them by their name.


Previous Post Next Post

Contact Form