Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

amitsolanki24_'s avatar

API resource PATCH and delete method not working

When I create my APIs like this than patch and delete api is working


		Route::get('/', 'index')->name('index');
		Route::post('/', 'store')->name('store');
        Route::patch('/{id}', 'update')->name('update');
        Route::delete('/{id}', 'destroy')->name('destroy');
      

But when I create my APIs like this than patch and delete method are not working why? I have cleared route, config and also try to optimize project many times

It's giving error PATCH method is not supported , supported method HEAD|GET


    Route::apiResource('/', CourseController::class)->except('show');

0 likes
8 replies
tykus's avatar
tykus
Best Answer
Level 104

I would suspect you are trying to use the PATCH and DELETE route with an empty / null ID.

EDIT: I just realised that you are actually giving the apiResource nothing to define the wildcard parameters because the URI is /, so... define a parameter:

Route::apiResource('/', CourseController::class)->except('show')->parameters(['' => 'id']);

or, give it a prefix segment

Route::apiResource('courses', CourseController::class)->except('show'); // {course} wildcard
1 like
amitsolanki24_'s avatar

@tykus thanks It works.

I think this issue is occured due to prefix method

My old code like this


Route::prefix('courses')->group(function () {

   Route::apiResource('/', 
   CourseController::class)->except('show');
});
tykus's avatar

@amitsolanki24_ absolutely no need for a prefix in that example 🤦‍♂️ This is all you needed

Route::apiResource('courses', CourseController::class)->except('show');

Mark the thread solved if you're all set

Please or to participate in this conversation.