Ad

Laravel 5.1 NotFoundHttpException In RouteCollection.php Line 161:

- 1 answer

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' => '[email protected]' ]);
Route::get('quiz/token/{quizByToken}', [ 'as' => 'quiz.token', 'uses' => '[email protected]' ]);
Route::get('quiz/code/{quizByCode}', [ 'as' => 'quiz.code', 'uses' => '[email protected]' ]);
Route::get('quiz/id/{quiz}/players', [ 'as' => 'quiz.players', 'uses' => '[email protected]' ]);
Route::get('quiz/token/{quizByToken}/players/highscore', [ 'as' => 'quizzes.player.highscore', 'uses' =>    '[email protected]' ]);
Route::put('quiz/nextQuestion/{quizByToken}', [ 'as' => 'quizzes.nextQuestion', 'uses' => '[email protected]' ]);
Route::get('quiz/poll/{quiz}', [ 'as' => 'quizzes.poll', 'uses' => '[email protected]' ]);
Route::put('quiz/poll/token/{quizByToken}/delay-current/{delayTime}', [ 'as' => 'quizzes.delayTime', 'uses' => '[email protected]' ]);

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
Ad

Answer

You are using the following route:

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

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.

Ad
source: stackoverflow.com
Ad