5

I have a route - let's call it stats. Here is what my routing currently looks like:

Route::get('stats', 'StatsController@index');
Route::get('stats/{query}', 'StatsController@store');

My goal is to show stat data if someone visits /stats and to store stat data if someone visits a URL similar to /stats?name=John&device=Android.

How would I then route if there is a query string attached to my namespace stats?

Something like this?

Route::get('stats/?name=*&device=*', 'StatsController@store');
sparecycle
  • 2,038
  • 5
  • 31
  • 58

1 Answers1

6

routes.php

Route::get('stats', 'StatsController@index');

StatsController

public function index()
{
    if(Input::has('name') and Input::has('device')))
        return $this->store();

    // Show stat ...
}

public function store()
{
    $input = Input::only('name', 'device');

    // Store stat ...
}

although it seems a pefect scenario for a RESTFUL controller. Whoever is sending the input should do it with a POST request

Jeff Puckett
  • 37,464
  • 17
  • 118
  • 167
Javi Stolz
  • 4,720
  • 1
  • 30
  • 27