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!