How to Solve Target Class Does Not Exist In Laravel 8

tutspack laravel
Spread the love

Hello Artisan,

In this tutorial, I will explain how we can solve the target class does ‘t exist in Laravel 8. You know recently laravel 8 was released some days ago. They changed the routing system a bit from other versions of Laravel.

In this tutorial we will solve laravel 8 routing problem like target class app/http/controllers does not exist. See the below code to solve this BindingResolutionException Target class does not exist.

Example code : 

use App\Http\Controllers\YourController;

Route::get('/', [YourController::class, 'anyMethod']);

So in Laravel 8 you have to show the path of your controller. You can use route group to avoid path as like below.

Route::namespace('App\Http\Controllers')->middleware('guest')->group(function () {
    Route::prefix('')->group(function () { //you can use prefix if you want
      Route::get('/', 'YourController@anyMethod');

Or if your are not happy with the above system and you would like to use it like laravel 7 then follow the below tips. go to your route service provider and update the code like below.


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

// the add this namespace like below

 $this->routes(function () {

now you can simply use like laravel 7 or other version

Route::get('/', 'YourController@anyMethod');

Hope it can be help you.

Spread the love

About Anisur Rahman Shahin

Hello. My name is Shahin. I'm a tech enthusiast guy. Personally, I’m an Optimistic and always in hurry kinda person. I'm a freelance web developer. I am working at Zakir Soft as Laravel Developer. My Portfolio website:

View all posts by Anisur Rahman Shahin →

Leave a Reply

Your email address will not be published.