Re-organising Laravel applications with PSR-4

However, as your application grows, you'll likely find it difficult to structure without namespaces. Larger applications typically end up with a structure like so:

app/

commands/

config/

controllers/

database/

MyApp/

Models/

Repositories/

Services/

storage/

tests/

views/

A bit confusing. You might move commands and controllers into namespaces as well, only to end up with much longer route configurations and sadness.

Fortunately, with PSR-4 we can restore the situation. PSR-4's autoloader allows us to map namespaces to arbitrary paths, which unlike PSR-0 don't contain any of the namespace. For example, we can modify composer.json to namespace everything in the default Laravel classmap, while retaining the simple structure: