Target Class Does Not Exist In Laravel 8

As you all know laravel 8 already released and you can see there are many changes and update in laravel 8 version. many laravel users are facing issue in their new Laravel 8 version when they try to load their routes in web.php and they run into an Exception that says something like “Target class [postController] does not exist”.

Target Class Does Not Exist In Laravel 8
Target Class Does Not Exist In Laravel 8

Upto Laravel 7, the RouteServiceProvider.php file had the below code:

here, namespace variable has stored ‘App\Http\Controllers’ and declared in middleware and prefix route as below.

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

But, In laravel 8 the $namespace variable was removed and the Route declaration changed as below:

protected $namespace = null;

Read Also : Dropzone Image Upload Tutorial In Laravel 6/7

So, Here is 2 different solution for target Class Does Not Exist.

1) Add namespace manually

In this process you need to add value/path in $namespace variable and you need to declare in route as well like below.

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

Now run again your app all codes are working fine without “Target Class Does Not Exist” error

2) Using Full Namespace in your Routes

In this solution you can use full namespace or changing all your route declarations like below code,

Route::resource('posts','App\Http\Controllers\PostController');

Here you need to add full path of your controller.

Read Also : Laravel 8 CRUD Operation Example

Thanks for reading !!

Please Don’t Forgot Like, Share and Claps.

Follow on medium : Websolutionstuff

--

--

I am Laravel and PHP Developer. I have also Good Knowledge of JavaScript, jQuery, Bootstrap and REST API. Visit Website: http://websolutionstuff.com/

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Websolutionstuff

I am Laravel and PHP Developer. I have also Good Knowledge of JavaScript, jQuery, Bootstrap and REST API. Visit Website: http://websolutionstuff.com/