Laravel 6.0 php artisan route:list returns “Target class [App\Http\Controllers\SessionsController] does not exist.”
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
Route::get('registration/create', 'RegistrationController@create')
it is now:
Solution 1: Classname representation
use App\Http\Controllers\RegistrationController;
Route::get('/', [RegistrationController::class, 'create']);
Solution 2: String syntax
or as a string syntax (full namespaces controller name):
Route::get('/', 'App\Http\Controllers\RegistrationController@create');
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
class RouteServiceProvider extends ServiceProvider
{
/* ... */
/** ADD THIS PROPERTY
* If specified, this namespace is automatically applied to your controller routes.
*
* In addition, it is set as the URL generator's root namespace.
*
* @var string
*/
protected $namespace = 'App\Http\Controllers';
/**
* Define your route model bindings, pattern filters, etc.
*
* @return void
*/
public function boot()
{
$this->configureRateLimiting();
$this->routes(function () {
Route::middleware('web')
->namespace($this->namespace) // <-- ADD THIS
->group(base_path('routes/web.php'));
Route::prefix('api')
->middleware('api')
->namespace($this->namespace) // <-- ADD THIS
->group(base_path('routes/api.php'));
});
}
/* ... /*
}
See also https://laravel.com/docs/8.x/routing#basic-routing or https://laravel.com/docs/8.x/upgrade (search for "Routing").
For those who have similar issue with Illuminate\Contracts\Container\BindingResolutionException : Target class [<className>] does not exist.
message, this also could be helpful:
composer dump-autoload
Run this command
php artisan config:cache