1# How to register utilities class on Laravel 5.8
2# File: composer.json
3# ref: https://stackoverflow.com/questions/28290332/best-practices-for-custom-helpers-in-laravel-5
4"autoload": {
5 "classmap": [
6 ...
7 ],
8 "psr-4": {
9 "App\\": "app/"
10 },
11 "files": [
12 "app/helpers.php" // <---- ADD THIS
13 ]
14},
15
16 # Then run: `composer dump-autoload`
11. Create a helpers.php file in your app folder and load it up with composer:
2
3"autoload": {
4 "classmap": [
5 ...
6 ],
7 "psr-4": {
8 "App\\": "app/"
9 },
10 "files": [
11 "app/helpers.php" // <---- ADD THIS
12 ]
13},
14
152. After adding that to your composer.json file, run the following command:
16 composer dump-autoload
17
183. If you dont like keeping your helpers.php file in your app directory
19(because it is not a PSR-4 namespaced class file), you can do what the
20laravel.com website does: store the helpers.php in the bootstrap directory.
21Remember to set it in your composer.json file:
22
23"autoload": {
24 ..........
25
26 "files": [
27 "app/Helpers/helpers.php"
28 ]
29
30 ..............
31}
1"autoload": {
2 "files": [
3 "app/helpers.php"
4 ],
5 "classmap": [
6 "database/seeds",
7 "database/factories"
8 ],
9 "psr-4": {
10 "App\\": "app/"
11 }
12},
13
1"autoload": {
2 "classmap": [
3 "database/seeds",
4 "database/factories"
5 ],
6 "psr-4": {
7 "App\\": "app/"
8 }
9},
10"autoload-dev": {
11 "psr-4": {
12 "Tests\\": "tests/"
13 }
14},
15