Tuesday, May 23, 2017

Laravel 5.4 Different routes pointing to different method but the response show the same page

I have an issue with my routes as some with different URLs and differents methods seems to use one method.

routes/web php :

Route::group(['middleware' => ['role:utilisateur,usage']], function()
{
     Route::group(['prefix' => 'qcm'], function()
     {
      Route::get('/', 'ModuleController@index');
      Route::get('{id?}', 'ModuleController@qcm');
      Route::post('answer', 'ModuleController@putAnswer');
      Route::get('result', 'ModuleQCMController@getResult');
      Route::get('get-question', 'ModuleController@getQuestion');
     });
}

ModuleController.php

class ModuleController extends Controller
{

  public function index()
  {
    return View::make('qcm.index')
  }


  public function qcm($id)
  {
      return View::make('qcm.qcm');
  }

  public function getQuestion()
  {
    return response()->json(['question' => 'test?']);
  }

  public function putAnswer(Request $request)
  {
    return response()->json(["result" => "next"], 200);
  }


  public function getResult()
  {
    return View::make('qcm.result');
  }
}

When I call test.com/qcm/result, it seems to call test.com/qcm/{id} instead and returns its view and I don't know why as php artisan route:list shows that the routes are pointing to the good methods.

Does anyone knows why my code is producing such results ? Have I missed something ?

Thank you in advance for your help.



via J.K Onew

Advertisement