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');
1
  • Check if Input is empty Commented Jul 2, 2014 at 19:15

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.