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

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

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

twosocks twosocks Joined 28 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.

© 2024 Laravel.io - All rights reserved.