In Laravel, I can't find my controller after rearranging the file and folder structure in app/http/controller. I wanted to organize my controller files due to their large number. Here's how it looks now.
Then, when I want to use the following API:
Route::post('/jadwal-dokter', [DokterController::class, 'jadwaldokterterpilih']);
I'm getting this response:
Target class [App\Http\Controllers\DokterController] does not exist.
This is how I connect my api.php to my controller:
use App\Http\Controllers\DetailPasienController;
use App\Http\Controllers\dokter\DokterController;
use App\Http\Controllers\JadwalPoliController;
use App\Http\Controllers\PasienController;
use App\Http\Controllers\PoliController;
use App\Models\jadwal_poli;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
But when i change the DokterController directory to
use App\Http\Controllers\DokterController;


your namespaces in the begining of the controller file should match the herirechy of the data sturcture
it should implement PSR-4 autoloading standard.
check laravel doc for more details
so namespace for DokterController should be
and the use should be:
further try to refactor your code in your route file . Instead of calling controller during defining each route separately you should use