I am using Laravel 6.0 and I try to list all my routes with artisan route:list
, but it fails and returns:
Illuminate\Contracts\Container\BindingResolutionException : Target
class [App\Http\Controllers\SessionsController] does not exist.at /home/vagrant/code/vendor/laravel/framework/src/Illuminate/Container/Container.php:806
802|
803| try {
804| $reflector = new ReflectionClass($concrete);
805| } catch (ReflectionException $e) {
> 806| throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e);
807| }
808|
809| // If the type is not instantiable, the developer is attempting to resolve
810| // an abstract type such as an Interface or Abstract Class and there isException trace:
1 Illuminate\Foundation\Console\RouteListCommand::Illuminate\Foundation\Console{closure}(Object(Illuminate\Routing\Route))
[internal]:02 ReflectionException::("Class App\Http\Controllers\SessionsController does not exist")
/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Container/Container.php:8043 ReflectionClass::__construct("App\Http\Controllers\SessionsController")
/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Container/Container.php:804
Up to now I just have a very simple web.php routes file:
Route::get('/', function () {
return view('index');
});
Route::prefix('app')->group(function () {
// Registration routes
Route::get('registration/create', 'RegistrationController@create')->name('app-registration-form');
});
// Templates
Route::get('templates/ubold/{any}', 'UboldController@index');
Any idea how I could debug this issue?
Best Answer
I was upgrading from Laravel 7 to Laravel 8 (Laravel 8 is still a few days in development) and also had this issue.
The solution was to use a classname representation of the controller in the route:
So in web.php instead of
it is now:
Solution 1: Classname representation
Solution 2: String syntax
or as a string syntax (full namespaces controller name):
Solution 3: Return to previous behaviour
As this should issue should only happen if you upgrade your application by creating a brand new laravel project you can also just add the default namespace to the RouteServiceProvider:
app/Providers/RouteServiceProvider.php
See also https://laravel.com/docs/8.x/routing#basic-routing or https://laravel.com/docs/8.x/upgrade (search for "Routing").