Home » Laravel 8: Target Class Controller Does Not Exist

Laravel 8: Target Class Controller Does Not Exist

Last updated on January 6, 2021 by

In this problem-solving article, we will solve the Laravel 8 target class controller does not exist an issue. Don’t panic, it has a very simple solution so bear with me.

Laravel 8: Target Class Controller Does Not Exist

The Laravel 8 introduced lots of changes in its releases. So some of the developers don’t aware of those changes. That’s why you guys are facing some issues.

Laravel 8 has introduced Routing Namespace Updates, in that they removed the automatic namespace adding features from your routes/* files. Let’s see it by example.

routes/web.php or routes/api.php In Laravel <= 7 version

Route::get('/home', 'HomeController@index');

So in the above example, we can use HomeController without specifying it’s namespace like app/Http/Controller/HomeController@index in Laravel older versions. But it has now changed in Laravel version 8.

Now, we need to include the namespaces into the route files like below:

routes/web.php In Laravel 8 version

use App\Http\Controllers\HomeController;

Route::get('/home', [HomeController::class, 'index']);
// or
Route::get('/home', 'App\Http\Controllers\HomeController@index');

That’s it. This will resolve your issue. But hang on! What if you want to follow the old route mechanism in Laravel 8? Our answer is yes, you can also enable the old way in Laravel 8. Let’s see how to do it.

What If I Want To Follow Old Routing Way

  1. First, go to the app/providers/RouteServiceProvider.php
  2. In that file uncomment the protected $namespace = 'App\Http\Controllers'; line.
// protected $namespace = 'App\\Http\\Controllers';

to 

protected $namespace = 'App\\Http\\Controllers';
laravel 8 target class controller does not exist

Additionally, read our guide:

  1. Laravel One To One Relationship Tutorial
  2. Laravel One To Many Relationship Tutorial With Example
  3. Database Records Update In Laravel
  4. Best Way to Remove Public from URL in Laravel
  5. Error After php artisan config:cache In Laravel
  6. Specified Key Was Too Long Error In Laravel
  7. AJAX PHP Post Request With Example
  8. How To Use The Laravel Soft Delete
  9. How To Add Laravel Next Prev Pagination
  10. How To Print Or Debug Query In Laravel
  11. Difference Between Factory And Seeders In Laravel
  12. Laravel: Increase Quantity If Product Already Exists In Cart
  13. Laravel DataTables Tutorial With Example
  14. Laravel Send Mail From Localhost
  15. How To Convert Word To PDF In Laravel
  16. Laravel Multiple Where Conditions With Example

That’s it for now. We hope this article helped you to solve the Laravel 8 target Class Controller does not exist an issue.

Please let us know in the comments if everything worked as expected, your issues, or any questions. If you think this article saved your time & money, please do comment, share, like & subscribe. Thank you in advance. 🙂 Keep Smiling! Happy Coding!

 
 

10 thoughts on “Laravel 8: Target Class Controller Does Not Exist”

  1. Itѕ like you rеad my mind! You appear t᧐ know so much about this, like you
    wrote the book in it or something. I think that
    you could do with a few рics to drive the message home a little Ьit, but otһer
    than that, thіs is magnificent blog. An excellent rеad.
    I will certainly be Ьack.

    my web blog;

    Reply
  2. my problem is that there are some routes that work and others do not, what is the reason for that? if they are of the same class I do not understand why some do not work

    Reply
    • Hi Daniel,

      Would you please share more information regarding your routes with us? I suspect, your routes might be overridden by other routes that’s why it’s not working. You should check the optional parameter routes first.

      Reply

Leave a Comment