While Working on a project using Laravel 4 to be precise, I decided that i wanted to make my own helper file to house my custom functions.. one of which is this below...
function pr($ar=array(), $bool=false){
echo '<pre>';
print_r($ar);
echo '</pre>';
if($bool){
exit;
}
}
in my composer.json file, just after the autoload: classmap , i added myne, autoload:files -arrar and included my custom file, app/helpers as illustrated below..
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
],
"others":[
"app/helpers.php"
]
and i switched to my terminal window and ran the following commands
composer dump-autoload -o
but i still got errors that my pr() function was undefined... then i tried the artisan alternative... [-o ] to optimize the files
php artisan dump-autoload
but still it refused to work... and then i changed the array name from
"others":[
"app/helpers.php"
]
to
"files":[
"app/helpers.php"
]
then i got the desired response, my code could now see the custom function i wrote, please i'd like to know if there is a pattern i was supposed to follow or otherwise, in my case, i mistook " files ", for " others " and i got errors, but incase, what did i miss here, all i see is just a name-string value for the array representation....
This is how composer works. In autoload
section you need to use files
when you want to load some files. In my Laravel 5 project I have for example:
"autoload": {
"classmap": [
"database",
"tests/TestCase.php"
],
"psr-4": {
"App\\": "app/",
"verify\\": "verify/"
},
"files": [
"app/Helpers/functions.php"
]
},
If you look at documentation you will see that you need to use files
to load any extra files by autoloader.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With