2015-12-12 21 views
0

我想爲傳入請求附加一個新的GET參數。我該怎麼做呢?Laravel:設置傳入請求的GET參數

這是我曾嘗試和不工作,

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

我是否需要寫這個中間件?即使我這樣做,我該如何設置GET參數key

回答

1

找到了答案,我的問題,有mergereplace方法,我們可以用它來修改輸入參數

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

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

This Works。

0

您可以通過添加一個問號添加路由參數

Route::get('teams/{param}', '[email protected]'); 
,如果你想讓它可選

路線::得到( '團隊/ {PARAM}?',「TeamController @指數');

而且你可以在你的控制器得到它

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

謝謝,但我發現'Input :: merge'方法正是我想要的。 – Rao