Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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);
like image 686
PhillipMcCubbin Avatar asked Sep 09 '20 08:09

PhillipMcCubbin


2 Answers

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.

like image 54
PhillipMcCubbin Avatar answered Sep 17 '22 15:09

PhillipMcCubbin


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

like image 39
lagbox Avatar answered Sep 19 '22 15:09

lagbox