8

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);
PhillipMcCubbin
  • 495
  • 1
  • 4
  • 10
  • I had a similar problem installing laravel 8 from `dev-develop` but today laravel announced version 8 now released. may have been repaired. although I haven't tried it yet. – Aslam H Sep 09 '20 at 08:48
  • Yes. This is a fresh installation of version 8, just released today. – PhillipMcCubbin Sep 09 '20 at 11:19

2 Answers2

19

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.

PhillipMcCubbin
  • 495
  • 1
  • 4
  • 10
9

If this is a fresh install of Laravel 8, there is no namepsace defined in the RouteServiceProvider to be applied to the your routes. You can try to wrap the Auth::routes() call in a route group that declares the namespace App\Http\Controllers, or go about this in a different way. (assuming you have installed laravel/ui)

Route::namespace('App\Http\Controllers')->group(function () {
    Auth::routes();
});

If you want to know how to deal with the lack of namespace being defined for your routes:

https://stackoverflow.com/a/63808132/2109233

lagbox
  • 48,571
  • 8
  • 72
  • 83