I have created class Helper
with path App\\Http\\Helpers\\
:
You can achieve this in a straight forward way by following these steps.
Step 1
Create your class file in your desired path (example: app/Helpers/Helper.php
) and define the class
Step 2
Modify composer.json
file by adding your file within the entry of the autoload
key
"autoload": {
"prs-4": {
"App\\": "app/"
},
"files": [
"app/Helpers/Helper.php"
]
}
Note that you are not changing anything apart from including this entry: "files": ["app/Helpers/Helper.php"]
.
Save the file.
Step 3
Run this command from your root directory:
composer dump-autoload
it refreshes the autoload cache.
Step 4
You can now use your class from anywhere including blade
This way, you can also create global functions as well.
- 热议问题