'Target class controller [controllerName] not found in Laravel 8
When I hit my register route using Postman, it gave me the following error:
My api.php route:
Route::get('register', 'Api\RegisterController@register');
Here is my controller:
Solution 1:[1]
It should be changed to:
Route::get('register', [RegisterController::class, 'register']);
Solution 2:[2]
first, in the route add the controller name.
use App\Http\Controllers\RegisterController;
In the route use like this way
Route::get('register', [RegisterController::class, 'register']);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Hasan Mahmud |
Solution 2 | Dip Ghosh |