Nagendra Rao
Nagendra Rao

Reputation: 7152

Laravel: Set incoming request's GET param

I want to append a new GET param to incoming request. How do I do this?

This is what I have tried and is not working,

Route::group(['prefix' => 'api'], function () {
  $_GET['key'] = getKeyForSession();
  Route::get('teams', 'TeamController@index');
});

Do I need to write a middleware for this? Even if I do, how do I set the GET param key?

Upvotes: 0

Views: 127

Answers (2)

Nagendra Rao
Nagendra Rao

Reputation: 7152

Found the answer to my question, there is merge and replace methods which we can use to modify input parameters

Example: Input::merge(['key', 'value']);

Route::group(['prefix' => 'api'], function () {
  Input::merge(['key' => getKeyForSession()]);
  Route::get('teams', 'TeamController@index');
});

This works.

Upvotes: 1

Nehal Hasnayeen
Nehal Hasnayeen

Reputation: 1223

you can add a route parameter

Route::get('teams/{param}', 'TeamController@index');

if you want to make it optional by adding a question mark

Route::get('teams/{param?}', 'TeamController@index');

And you can get it in your controller

public function index($param)
{
    // your code....
}

Upvotes: 0

Related Questions