Laravel: 设置传入请求的 GET 参数

Laravel: Set incoming request's GET param

我想将新的 GET 参数附加到传入请求。我该怎么做?

这是我已经尝试过但没有用的方法,

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

我需要为此编写一个中间件吗?即使我这样做了,如何设置 GET 参数 key?

你可以添加路由参数

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

如果你想通过添加问号使其成为可选的

路线::获取('teams/{param?}', 'TeamController@index');

你可以在你的控制器中获取它

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

找到我问题的答案,有merge and replace个方法可以用来修改输入参数

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

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

这有效。