Support the ongoing development of Laravel.io →
Configuration Architecture
Last updated 2 years ago.
0

Do you mean a library or a package?

Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

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!

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

kyoukhana kyoukhana Joined 28 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.