2017-02-26 158 views
0

我在多個參數傳遞給由路由控制器在laravel 5

路線:

Route::get('feed/{type?}/{first?}/{second?}/{third?}', ['as' => 'feed', 'uses' => '[email protected]']); 

控制器:

public function feed(Request $request, $type, $first, $second, $third) 
{ 
... 

但這農產品錯誤:

ErrorException in PostController.php line 209: 
Missing argument 3 for App\Http\Controllers\PostController::feed() 

我做得不好?我忘了什麼? 謝謝。

回答

2

按照Laravel Docs

Make sure to give the route's corresponding variable a default value

所以它應該是這樣的:

public function feed(Request $request = null, $type = null, $first = null, $second = null, $third = null) 
{ 
... 

您可以將其替換null您選擇的默認值。

1

你應該申報的參數作爲可選太像

public function feed(Request $request, $type = '', $first = '', $second = '', $third = '') 
{