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

uniqueginun's avatar

Inertia throw method is not supported for this route when redirecting after delete request

Hello guys.

I have a delete route defined in api.php as bellow:

Route::delete(
    'survey/{survey}/question/{question}', 
    SurveyQuestionDeleteController::class
)->name('survey.question.delete');

I'm calling this wrote in the frontend like so:

export const useDeleteQuestion = (surveyId, questionId) => {

   const isDeleting = ref(false);

   const deleteQuestion = async () => {
      
      isDeleting.value = true;
      const payload = { survey: surveyId, question: questionId };

      Inertia.delete(route('survey.question.delete', payload), {
         preserveScroll: true,
         onError: (error) => handleError(error),
         onSuccess: (res) => {
            console.log(res);
         },
         always: () => isDeleting.value = false,
      });

      isDeleting.value = false;
   }

   return {
      isDeleting,
      deleteQuestion,
   };
}

and here's the controller function that handles the request:

public function __invoke(Survey $survey, Question $question)
    {

        DB::beginTransaction();

        try {
            $survey->questions()->detach($question->id);

            SurveyQuestionAnswer::where([
                'survey_id' => $survey->id,
                'question_id' => $question->id,
            ])->delete();
            
            DB::commit();

            $flash = [
                'message' => 'Question deleted successfully',
                'type' => 'success',
            ];
        } catch (\Throwable $th) {
            Log::error($th->getMessage());
            DB::rollBack();
            $flash = [
                'message' => 'Error deleting question',
                'type' => 'error',
            ];
        }

        return Redirect::route('surveys.design', $survey)
                ->with('flash', $flash);
    }

now the issue is the deletion successfully done, but the redirect part is throwing this exception even though this route that I redirect to is defined in web.php as so:

Route::middleware(['auth:sanctum', 'verified'])->group(function () {
    Route::prefix('surveys')->as('surveys.')->group(function () {
        Route::get('/{survey}/desgin', SurveyDesignController::class)->name('design');
        Route::post('/{survey}/desgin', SurveyDesignStoreController::class)->name('design');
    });
});
0 likes
6 replies
Sinnbeck's avatar

You have two routes with the same name.. Change one

Route::middleware(['auth:sanctum', 'verified'])->group(function () {
    Route::prefix('surveys')->as('surveys.')->group(function () {
        Route::get('/{survey}/desgin', SurveyDesignController::class)->name('design');
        Route::post('/{survey}/desgin', SurveyDesignStoreController::class)->name('design.store');
    });
});
uniqueginun's avatar

@Sinnbeck one is post and the other is get. But I did remove the post one but still nothing changed

Sinnbeck's avatar

@uniqueginun What error are you getting? And are you sure you are using axios and not Inertia.post() ?

Inertia is made to use normal web routes.

uniqueginun's avatar

@Sinnbeck I use Inertia.delete for my delete route and I get the error on the title that this route is not allowed for delete

uniqueginun's avatar

@Sinnbeck

Route::delete(
    'survey/{survey}/question/{question}', 
    SurveyQuestionDeleteController::class
)->name('survey.question.delete');

Please or to participate in this conversation.