I just downloaded Laravel 5 and started migrating to it. However, I find the required use of namespaces really annoying.
I don't feel like I am getting much from it, other than cluttering my code.
How can I disable the namespacing requirement?
I just downloaded Laravel 5 and started migrating to it. However, I find the required use of namespaces really annoying.
I don't feel like I am getting much from it, other than cluttering my code.
How can I disable the namespacing requirement?
I don't think you should disable or remove namespaces. The main reason for namespacing is to avoid conflicts with classes that have the same name. As soon as an application gets larger you will have classes that have the same name. Example from the Framework source:
Illuminate\Console\Application
andIlluminate\Foundation\Application
Both are called the same. Only because of the namespacing you can import the right class. Of course you could also name them:
ConsoleApplication
andFoundationApplication
But while the namespace normally is only used when importing a class at the top of a file:
The name itself is used everywhere in the code. That's something that really clutters up your code, too long class names.
Besides the naming thing, namespaces also encourage better structure and help with knowing where your files are. That's because Laravel's default structure is
PSR-4
compliant. That means if you have a controllerApp\Http\Controllers\HomeController
you can be certain that you will find aHomeController.php
underapp/Http/Controllers
.Maybe it doesn't make sense for the current project but getting used to namespaces will help you tackle bigger projects in the future
I don't know Sublime Text that well, but CodeIntel might have auto import. Otherwise consider switching to another editor / IDE. I can highly recommend JetBrains PhpStorm
In the end, if you still don't want to use namespaces, keep using Laravel 4 or search for another framework that follows less good practices...
Removing namespaces from your app classes
While a totally don't recommend this, it is possible to at least remove some of the namespacing in your application.
For example the default controller namespace
App\Http\Controllers
can be changed to no namespace at all inRouteServiceProvider
:And for your models you can just remove the namespace in the file and your good. But keep in mind that without namespaces PSR-4 autoloading won't work anymore. You will have to autoload your files using
classmap
incomposer.json
You can avoid using namespaces for own classes by defining them in the global namespace in your composer.json file. Like this:
You will also have to change your app/Providers/RouteServiceProvider.php to:
for routing to work.