Library. I have a php class i wrote a while back I just what to have the ability to call it within routes.php file.
If its just a one-off file you can move it somewhere into your application directory (such as app/yourclass.php
). From there you can do a simple require 'yourclass.php
from within routes.php
.
Alternatively you can autoload it using composer. To do this open composer.json
and locate the autoload
section (it is near the bottom). In that section you will see an array called files
. It will already have Laravel's helpers.php
file in there. Add your file path to the array so that it becomes
"files":[
"src/Illuminate/Support/helpers.php",
"app/yourclass.php"
],
After this just run composer update
and your class will be available throughout your project.
Use whichever method is easiest for you. The point being if its a single class in a PHP file creating a package might be overkill. Laravel is written in PHP so any of PHP's features (such as require
) are still available.
Hope this helps!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community