Target class controller does not exist – Laravel 8

Here is my controller:

<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class RegisterController extends Controller
{
    public function register(Request $request)
    {
        dd('aa');
    }
}

As seen in the screenshot, the class exists and is in the correct place:

enter image description here

My api.php route:

Route::get('register', 'Api\RegisterController@register');

When I hit my register route using Postman, it gave me the following error:

Target class [Api\RegisterController] does not exist.


Update:

Thanks to the answer, I was able to fix it. I decided to use the fully qualified class name for this route, but there are other options as described in the answer.

Route::get('register', 'App\Http\Controllers\Api\RegisterController@register');

22 Answers
22

Leave a Comment