I have a form which should go to the TestsController Controller and it's takeTest method, this is the code below that generated the form:
{{ Form::open(array('action' => 'TestsController@takeTest')) }}
The generated HTML:
<form method="POST" action="http://192.168.0.8/tests" accept-charset="UTF-8"
The routes declared in routes.php file:
Route::get('tests', 'TestsController@index');
Route::post('tests', 'TestsController@takeTest');
Route::post('tests', 'TestsController@processMarking');
It should go to takeTest method but it goes to the processMarking method instead. Why is this and how can it be fixed?
-
How do you expect it to differentiate between two routes with the same uri and request method?Steve– Steve2014年06月09日 21:20:28 +00:00Commented Jun 9, 2014 at 21:20
1 Answer 1
Because you have declared two routes using same URI/tests and same method (post) like this:
Route::post('tests', 'TestsController@takeTest'); // first
Route::post('tests', 'TestsController@processMarking'); // second
So the second route is overriding the first route. If you change the URI of your second route to something else then it'll work, for example:
Route::post('moretests', 'TestsController@processMarking');
You can't use same URI for two routes using same method (i.e. post in your case).
4 Comments
'action' => 'TestsController@takeTest' generated action="http://192.168.0.8/tests" URI as action.Form::open(array('action' => 'TestsController@takeTest')) it searched for value in the RouteCollection object and found tests as the key for TestsController@takeTest, that's it.