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');
});
});