close

[Solved] Target class [Api\RegisterController] does not exist

Hello Guys, How are you all? Hope You all Are Fine. Today I am trying to make routing but I am facing following error in my laravel 8 Target class [Api\RegisterController] does not exist in PHP. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Target class [Api\RegisterController] does not exist Error Occurs ?

I am trying to make routing but I am facing following error in my laravel 8.

Target class [Api\RegisterController] does not exist.

How To Solve Target class [Api\RegisterController] does not exist Error ?

  1. How To Solve Target class [Api\RegisterController] does not exist Error ?

    To Solve Target class [Api\RegisterController] does not exist Error This error occurs in Laravel 8 Here is Laravel 8 Official Message In previous releases of Laravel, the RouteServiceProvider contained a $namespace property. This property's value would automatically be prefixed onto controller route definitions and calls to the action helper / URL::action method. In Laravel 8.x, this property is null by default. This means that no automatic namespace prefixing will be done by Laravel In Laravel You have to use Route as given Below. Route::get('/register', 'App\Http\Controllers\[email protected]'); OR use App\Http\Controllers\UserController; Route::get('/register', [UserController::class, 'register']); Now, your error must be solved.

  2. Target class [Api\RegisterController] does not exist

    To Solve Target class [Api\RegisterController] does not exist Error This error occurs in Laravel 8 Here is Laravel 8 Official Message In previous releases of Laravel, the RouteServiceProvider contained a $namespace property. This property's value would automatically be prefixed onto controller route definitions and calls to the action helper / URL::action method. In Laravel 8.x, this property is null by default. This means that no automatic namespace prefixing will be done by Laravel In Laravel You have to use Route as given Below. Route::get('/register', 'App\Http\Controllers\[email protected]'); OR use App\Http\Controllers\UserController; Route::get('/register', [UserController::class, 'register']); Now, your error must be solved.

Solution 1: Laravel 8 Update RouteServiceProvider

Here is Laravel 8 Official Message:

“In previous releases of Laravel, the RouteServiceProvider contained a $namespace property. This property’s value would automatically be prefixed onto controller route definitions and calls to the action helper / URL::action method. In Laravel 8.x, this property is null by default. This means that no automatic namespace prefixing will be done by Laravel.”

In Laravel You have to use Route as given Below.

Route::get('/register', 'App\Http\Controllers\[email protected]');

OR

use App\Http\Controllers\UserController;

Route::get('/register', [UserController::class, 'register']);

Now, your error must be solved.

Solution 2: uncomment this line

Just uncomment This line in your app\Providers\RouteServiceProvider.php path and remove the comment of this line.

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

Now, you can use old routing method in your laravel 8.

Summary

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?

Also, Read

Please Rate Our Solution to Motivate Us For Give Our Best

Leave a Comment