Laravel 5.1 NotFoundHttpException in RouteCollecti

2019-09-14 11:36发布

I get this error when I try to access delayTime method. I can't see what I am doing wrong. I have the routes setup like this:

Route::post('quiz', [ 'as' => 'quiz', 'uses' => 'QuizController@create' ]);
Route::get('quiz/token/{quizByToken}', [ 'as' => 'quiz.token', 'uses' => 'QuizController@getQuizByToken' ]);
Route::get('quiz/code/{quizByCode}', [ 'as' => 'quiz.code', 'uses' => 'QuizController@getQuizByCode' ]);
Route::get('quiz/id/{quiz}/players', [ 'as' => 'quiz.players', 'uses' => 'QuizController@getQuizPlayers' ]);
Route::get('quiz/token/{quizByToken}/players/highscore', [ 'as' => 'quizzes.player.highscore', 'uses' =>    'PlayerController@highscore' ]);
Route::put('quiz/nextQuestion/{quizByToken}', [ 'as' => 'quizzes.nextQuestion', 'uses' => 'QuizController@nextQuestion' ]);
Route::get('quiz/poll/{quiz}', [ 'as' => 'quizzes.poll', 'uses' => 'QuizController@currentQuestion' ]);
Route::put('quiz/poll/token/{quizByToken}/delay-current/{delayTime}', [ 'as' => 'quizzes.delayTime', 'uses' => 'QuizController@delayTime' ]);

Error message:

NotFoundHttpException in RouteCollection.php line 161 in RouteCollection.php line 161
at RouteCollection->match(object(Request)) in Router.php line 750
at Router->findRoute(object(Request)) in Router.php line 659
at Router->dispatchToRoute(object(Request)) in Router.php line 635
at Router->dispatch(object(Request)) in Kernel.php line 236
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139

1条回答
我想做一个坏孩纸
2楼-- · 2019-09-14 11:57

You are using the following route:

Route::put(
    'quiz/poll/token/{quizByToken}/delay-current/{delayTime}',
    [ 'as' => 'quizzes.delayTime', 'uses' => 'QuizController@delayTime'
]);

Which means when you submit the form, you've to pass a hidden input field named _token with value put in it, for example:

<form method='POST'>
    <input type="hidden" name="_method" value="PUT" />
    <!-- Other Fields -->
</form>

I'm sure you missed it. You may check Form Method Spoofing for more information on this topic.

查看更多
登录 后发表回答