Laravel's routing system for version 8 changed the way the ServiceProvider
. Previously the attribute $namespace
was declared in this way:
protected $namespace = 'App\Http\Controllers';
However, in version 8 the attribute is declared as null.
protected $namespace = null;
So the routes in version 8 must be declared in the following way:
<?php
//Se debe llamar al controllador
use App\Http\Controllers\UserController;
//De esta manera puede ser usado al momento de declarar la ruta.
Route::get('/user', [UserController::class, 'index']);
If you are working on a new project, you may not see much of a problem in adapting to version 8, but if you want to migrate a system in which you have hundreds or thousands of routes, changing all the routes one by one may not be a viable solution.
Can I stay on the old routing system while on Laravel version 8?
The answer is yes:
For this in the documentation you can get the following information:
Basically you have to make two changes to the file
app\Providers\RouteServiceProvider.php
:1. Declare the namespace attribute like this (which is nothing more than keeping it as it was in version 7.x):
2. In the boot method you must pass the declared attribute to the
namespace
nested method almiddleware('web')
andmiddleweare('api')
:In this way you can continue loading your routes as in version 7.x
Font: