Create a helpers.php
file in your app folder and load it up with composer:
"autoload": {
"classmap": [
...
],
"psr-4": {
"App\": "app/"
},
"files": [
"app/helpers.php" // <---- ADD THIS
]
},
After adding that to your composer.json
file, run the following command:
composer dump-autoload
If you don't like keeping your helpers.php
file in your app
directory (because it's not a PSR-4 namespaced class file), you can do what the laravel.com
website does: store the helpers.php
in the bootstrap directory. Remember to set it in your composer.json
file:
"files": [
"bootstrap/helpers.php"
]
Tip:
If you want to use the different file name instead of helpers
, you can change the file name and path.
Also, you can create multiple helper files.
It will look like this:
"autoload": {
"classmap": [
...
],
"psr-4": {
"App\": "app/"
},
"files": [
"app/Helpers/base.php", // <---- ADD THIS
"app/Helpers/metrics.php" // <---- Create `metrics.php` file in this path and add the path in composer.json file.
]
},
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…