Coming from a strong Java background, and migrating a CodeIgniter website, I really like the IoC and DI of Laravel. What I am struggling with is the file and directory structure that I have to create.
I am reading lots of tutorials and they all advertise to do the Right Thing™: ServiceProviders, the interfaces, the implementations, the whole lot. In 99% of the tutorials they show code that goes into file X.php, but they never show WHERE that file is placed. They all say "it doesn't matter where you place it because Laravel will automatically find it", but in practice this is not the case.
I like the namespaces, similar to the Java packages, but WHERE? When I create a directory in app/ at the same level as config, controllers, etc, to keep all my stuff together, and add the line to the global.php (ClassLoader::addDirectories(...)), I still get the dreaded class not found.
It's very confusing where to place all your files. Does anybody have a definitve way of placing files?
you need to add it to composer.json. and than do a composer dump. You can use every folder you create in app. I used Base and created different parts with namespaces inside it.
You can create a custom folder within the app
folder for all your own business logic. Maybe call it "MyApp" or a nickname for your application. You can use psr-4 to load anything within it inside composer.json
"autoload": {
"psr-4": {
"MyApp\\": "app/MyApp"
}
},
Then you don't need to add anything to start.php, or global.php keeping them clean
Thanks for the tips. I'll give them a shot!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community