Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Method in controller does not exist error – Laravel 9

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

What I am doing wrong?

enter image description here

>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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading