The error "Target class controller does not exist" in Laravel 8 typically occurs when Laravel is unable to locate the controller specified in your route definition.

When working with a new installation of Laravel 8, you may notice that your route groups do not have a namespace prefix applied to them, which is where your routes are typically loaded into.

Earlier versions of Laravel utilized the $namespace property within the RouteServiceProvider, which would automatically prefix controller route definitions and calls to the action helper / URL::action method. However, in Laravel 8.x, this property is null by default, resulting in no automatic namespace prefixing being performed by Laravel.

When the namespace prefixing feature is not being used in Laravel 8, you will need to refer to your controllers using their Fully Qualified Class Name (FQCN) in your routes.
use AppHttpControllersProductController;

Route::get('/users', [ProductController::class, 'index']);
// or
Route::get('/users', 'AppHttpControllersProductController@index');


Comments (0)
Leave a Comment

loader Posting your comment...