Hi, may be a silly question, but its my first project on Laravel, so a quick guidance would be helpful...
What is a best practice for classes that dont have their representation in the database, ie helper classes that are used to calculate the data? Its not a View, its not a Controller, it could be a Model if generated objects are actually persistent in the database, but they arent. Outside packages seem to tick all the boxes, but this would be integral part of an app that I wouldnt want to publish outside the app.
Also, no idea what tag to pick for this question :D
Put them anywhere you want.
I would suggest you put them in app/helpers.php
and then require
that file in app/start/global.php
or add them in app/helpers
(new folder) and then autoload that folder with composer.
"autoload": {
"classmap": [
...
"app/helpers",
...
]
},
Great, I'll go with directory version. Thanks!
Also consider PSR-4, also in composer.json:
"psr-4" : {
"YourNamespace\\" : "app/YourNamespace"
}
Don't forget to do composer dump-autoload in the terminal.
You can now drop in classes like this with no manual configuration required, or even touching composer:
// app/YourNamespace/Foo/bar.php
namespace YourNamespace\Foo;
class Bar{}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community