. Advertisement .
..3..
. Advertisement .
..4..
Running into errors while coding can be a scary experience, particularly when you are using a framework. Laravel is a good framework to use but it is complicated and can tend to come with errors sometimes. One common error that you might come across when using Laravel is “Target class controller does not exist in Laravel 8”. Read on to fix it.
How To Solve The Error “Target class controller does not exist in Laravel 8”?
When trying to create routing in Laravel 8, you might get the following error.
Target class [Api\RegisterController] does not exist.
To fix the error “Target class controller does not exist in Laravel 8,” follow these steps. You must use Route in Laravel 8 as shown below: Route::get(‘/register’, ‘App\Http\Controllers\[email protected]’); OR utilize App\Http\Controllers\UserController; Route::get(‘/register’, [UserController::class, ‘register’]); Now, you have fixed your problem.
Option 1
You must utilize Route in Laravel 8 as shown below:
Route::get(‘/register’, ‘App\Http\Controllers\[email protected]’);
Or
use App\Http\Controllers\UserController;
Route::get(‘/register’, [UserController::class, ‘register’]);
Now, you have resolved your issue.
Option 2: Uncomment the following line
Simply delete the comment from this line and uncomment it in your app\Providers\RouteServiceProvider.php path.
protected $namespace = ‘App\\Http\\Controllers’;
In Laravel 8, you can now utilize the old routing approach.
Conclusion
The error “Target class controller does not exist in Laravel 8” is a confusing error message. We hope this blog has helped clear the air around what this error message means and how to solve it. If you have more questions about this issue, please leave a comment below. Thank you for reading; we are always excited when one of our posts can provide useful information on a topic like this!
Leave a comment