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
So in the above example, we can use
HomeController without specifying it’s
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
- First, go to the
- In that file uncomment the
protected $namespace = 'App\Http\Controllers';line.
// protected $namespace = 'App\\Http\\Controllers'; to protected $namespace = 'App\\Http\\Controllers';
Additionally, read our guide:
- Laravel One To One Relationship Tutorial
- Laravel One To Many Relationship Tutorial With Example
- Database Records Update In Laravel
- Best Way to Remove Public from URL in Laravel
- Error After php artisan config:cache In Laravel
- Specified Key Was Too Long Error In Laravel
- AJAX PHP Post Request With Example
- How To Use The Laravel Soft Delete
- How To Add Laravel Next Prev Pagination
- How To Print Or Debug Query In Laravel
- Difference Between Factory And Seeders In Laravel
- Laravel: Increase Quantity If Product Already Exists In Cart
- Laravel DataTables Tutorial With Example
- Laravel Send Mail From Localhost
- How To Convert Word To PDF In Laravel
- 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”
Itѕ like you rеad mｙ 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;
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
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.
Thanks men, really helpful
We are glad to hear that. Thanks 🙂
Thank you, its work!
This method is still not working for me. I checked and updated the issue but it still shows me the error.
Let us know more about the error and we will try to provide solution
Many tks for your help!
You are welcome 🙂