Custom helper function in laravel

Helper function call intire page of website. If you want any kind of global function then you can use it or if you need any function or pies of code again and again many times, then you can use it. The first scenario you might want to include your helper functions is within the context of a Laravel application. Depending on your preference, you can organize the location of your helper file(s) however you want, however, here are a few suggested locations:

A. create a file inside app folder suppose name is helper.php

B. Goto to composer.json

"autoload" : {
   "files" : {
       "app\helpers.php"
   }
}

composer dump-autoload
helper.php

if(!function_exists('fun_abc')){
    function fun_abc($param1, $param2){

    }
}
controller.php

function students(Request $req){
   fun_abc('hi', 'kaise ho');
}

 

 

 

 

 

Leave a Reply