1

I'm trying to post a GET request to a laravel routes but I'm getting a 404 (Not Found)

ajax call

   axios.get('/statisticsJSON', {
        params: {
          annee: 2017,
          mois: 06,
          jour: 15,
        }
      })
      .then(function (response) {
        console.log('Les donnees via ajax');
        console.log( response.data);
      })
      .catch(function (error) {
        console.log(error);
      });

web.php

Route::get('/statisticsJSON/{annee}/{mois}/{jour}', 'EmploiController@showStatisticsJSON')
   ->name('statsJSON')
   ->where('annee', '^(19|20)\d{2}$')
   ->where('mois', '^(19|20)\d{2}$')
   ->where('jour', '^(19|20)\d{2}$');

controller

public function showStatisticsJSON(Request $request, $annee=null, $mois=null, $jour=null)
{
    //
    $annee = $request->get('annee');
    $mois = $request->get('mois');
    $jour = $request->get('jour');
    $emplois = Emploi::whereYear('POSTDATE', '=', $annee)
          ->whereMonth('POSTDATE', '=', $mois)
          ->whereDay('POSTDATE', '=', $jour)
          ->get();
    return response()->json(emplois ,200,[],JSON_PRETTY_PRINT);
}

link generated

http://localhost:8000/statisticsJSON?annee=2017&mois=6&jour=15
Papouche Guinslyzinho
  • 5,277
  • 14
  • 58
  • 101
  • 1
    Please don't say "post a get request", heh. POST and GET are two totally different types of HTTP request - very confusing terminology. – ceejayoz Jun 17 '17 at 22:18

1 Answers1

2

You are sending query parameters, not route parameters as it is. Laravel expects

http://localhost:8000/statisticsJSON/2017/6/15

in order for it to match. Build the url string for axios.get(my_url, first and omit the params: {}.