How to create helper file in laravel?

·

Laravel 7.2 routing with route group auth guard check with prefix

Hello to all, welcome to therichpost.com. In this post, I will tell you, How to create helper file in laravel? Laravel is one of the top php mvc framework. Helper file in laravel helps to create global functions and these all are use in all laravel project.

Here is the way to create helpers file in laravel:

1. First create the file app/helpers.php and add below code in it:

<?php
 // print_r for debugging
 function pr($x){
   echo "<pre>";
   print_r($x);
   echo "</pre>";
 }
?>


/********************************************/
2. Add below code into your composer.json file to call helpers.php file:

   "autoload": {
    "files": [
      "app/helpers.php"
    ]
   },

/********************************************/
3. Run below command into your composer and this command automatically add this file into your laravel project:

   $ composer dump-auto

There are so many code tricks in laravel and i will let you know all. Please do comment if you any query related to this post. Thank you. Therichpost.com

Comments

One response to “How to create helper file in laravel?”

  1. Julien Pitt Avatar
    Julien Pitt

    “app/Helper.php”

    to

    “app/helpers.php”