Support the ongoing development of Laravel.io →
posted 10 years ago
Configuration

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?

Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

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

Last updated 2 years ago.
0

Thanks for the tips. I'll give them a shot!

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

NLSurfMan nlsurfman Joined 14 May 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.

© 2025 Laravel.io - All rights reserved.