Laravel: The GET method is not supported for route. Supported methods: POST

68 views Asked by At

I got a weird problem and I couldn't find a similar case.

This is the error I get:

The GET method is not supported for route api/event/2/updatePoll/1. Supported methods: POST.

And when I scroll down on the Laravel Error Page, it shows the cUrl as a GET

The "weird" thing about it, I only get that error when my controller method looks like this

public function addVote(Request $request, string $id, string $pollId)
{
    $poll = Poll::find($pollId)->pollOptions();
    var_export($poll);
}

or alternativly

$poll = Poll::with(['pollOptions.pollOptionVotes'])->find($pollId);

When I do not query the pollOptions, the request is valid

This is the call in api.php

Route::post('/event/{id}/updatePoll/{pollId}', [EventController::class, 'addVote']);

And this is the Ajax call from my VUE3 App.

await apiClient().post(
        `/event/${event.value!.id}/updatePoll/${pollId}`,
        value
    )

I already tried

php artisan optimize 
php artisan route:clear
php artisan route:cache

Anyone got any idea? Why is "further" querying a problem?

0

There are 0 answers