I have defined the route in web.php
Route::name('complaints.')->prefix('complaints')->group(function() {
Route::get('/', [ComplaintController::class, 'index'])
->middleware('auth')
->name('index');
Route::get('/get-candidates', [ComplaintController::class, 'get-candidates'])
->middleware('auth')
->name('get-candidates');
});
And have created this method in ComplaintController
public function getCandidates(Request $request){
$candidatenames = [];
echo json_encode($candidatenames);
}
But when I try to access this url http://localhost/complaints/get-candidates i get this error Method App\Http\Controllers\ComplaintController::get-candidates does not exist.
What I am doing wrong?
>Solution :
Change either
Route::get('/get-candidates', [ComplaintController::class, 'get-candidates']) to
Route::get('/get-candidates', [ComplaintController::class, 'getCandidates']) or change your function name from getCandidates to get-candidates
