With name spacing, you need to tell your composer.json
what your namespaces are and where the code sits - once you have that, you only need to composer dump-autoload once
.
Once you crack that, points 2, 3 and 4 will be fixed.
For example, in your composer.json
you need to add a psr-4 reference that states what your top level name space is, and then where that code actually sits.
Say you have a name space called MyNameSpace
and you put your classes in /app/MyNameSpace/
folder, it would look like this:
"autoload": {
"classmap": [
...
],
"psr-4": {
"MyNameSpace\\": "app\MyNameSpace"
}
},
Add that, run composer dump-autoload
and now Composer knows where to look and then Laravel's autoloader will, in turn, know where to to look.
Jeffery Way did a good primer on it on Laracasts, and it's freely available: https://laracasts.com/lessons/psr-4-autoloading
If that wasn't clear enough, Phil Sturgeon did one too: http://philsturgeon.co.uk/blog/2014/01/autoloading-laravel-application-code-with-psr4
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community