I have a fresh installation of Laravel 9 and I tried to uncomment controller namespace in RouteServiceProvider.php. But in my api routes throw an error:
Undefined class 'MainController'
My controller is correctly placed under this namespace.
App\Http\Controllers
api.php file is like this.
Route::group(['prefix' => '/main'], function () {
Route::get('/', [MainController::class, 'index']);
});
Controller file is like this.
<?php
namespace App\Http\Controllers;
class MainController extends Controller
{
public function index()
{
return response()->json(['status'=>200,'message'=>'success']);
}
}
If I import the controller file to api routes file, it works as normal.