Laravel 8 - Route cannot find controllers: Target class [Auth\LoginController] does not exist

PhillipMcCubbin picture PhillipMcCubbin · Sep 9, 2020 · Viewed 8.1k times · Source

I went to take Laravel 8 for a spin today, but it seems the Route facade cannot find controllers anymore.

The route /home gives me this error:

Target class [HomeController] does not exist.

I get a similar error when I run: php artisan route:list

Illuminate\Contracts\Container\BindingResolutionException

Target class [Auth\LoginController] does not exist.

at C:\...\vendor\laravel\framework\src\Illuminate\Container\Container.php:811
811 throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e);

Answer

PhillipMcCubbin picture PhillipMcCubbin · Sep 9, 2020

Thanks to lagbox, I ended up adding namespace('App\Http\Controllers') to the web route in RouteServiceProvider boot method:

public function boot()
{
    $this->configureRateLimiting();

    $this->routes(function () {
        Route::middleware('web')
            ->namespace('App\Http\Controllers')
            ->group(base_path('routes/web.php'));

That did the trick for me. Any better solutions would be most welcome.