TALL Tales

Error: Target class [myController] does not exist

04 Oct, 2022

If you are coming from Laravel 7 and you're now using Laravel 8 you may come across this error message when using your routes:

Illuminate\Contracts\Container\BindingResolutionException
Target class [myController] does not exist.

This is because Laravel 8 does not have a namespace prefix applied to your route like it used to.

In order to fix this problem you can either:

  1. alter your routes so they have the prefix e.g.
Route::get('/posts', 'App\Http\Controllers\PostController@index');

or

use App\Http\Controllers\ PostController;

Route::get('/posts', [PostController::class, 'index']);

2 - set the value of the $namespace property within your RouteServiceProvider.

Go to app\Providers\RouteServiceProvider.php and uncomment out this line:

protected $namespace = 'App\\Http\\Controllers';

This should then solve the problem.