Search code examples
laravelapidingo-api

Dingo API routing does not pass in GET parameters when routing to controller


I have a Laravel Application and it uses Dingo Router:

 $api->get('/cash-flow', 'App\Http\Controllers\ReportController@cashFlowReport');

When my front-end calls this api, it gets 200 responses from OPTIONS & GET. However, it does not successfully pass in the GET variables.

 public function cashFlowReport(Request $request)
{
    $input = $request->all();
    return var_dump($input);
}

The response returns an empty array. I thought it was the Request class dependency but I think it would throw an error when it tries to access the parameter.

I have the Request Dependency:

use Illuminate\Http\Request;

Solution

  • If you are using nginx you will want to make sure the query string is actually making it through the 'rewrite'/'pretty url' process.

    From the Laravel installation documentation for Pretty Urls:

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    

    The ?$query_string part is important.

    Laravel Docs - Installation - Pretty Urls