Sometimes we need to create a helper function on the Laravel project to use a function on the whole project.
To create a helper function, we need to create a helper file in the following folder -
app\helpers\helpers.php
on that folder write your function like this -
<?php
if (!function_exists('abc')) {
function abc($parameter)
{
// statement
return xyz;
}
}
after that we need to add this folder in autoloader on -
composer.json
"autoload": {
"psr-4": {
///
},
"files":[
"app/helpers/helpers.php"
]
},
Once you add a new path to the files array, you need to dump the autoloader-
composer dump-autoload
Then you can access this "abc()" function from anywhere in this project.
Top comments (0)