Laravel 5:路由可选参数问题

时间:2015-07-15 12:38:29

标签: laravel-routing

我希望第二个参数作为可选参数。

路线:

Route::get('/offers/preview/{id}/{string?}', 'OfferController@preview');

控制器:

public function preview($id, $string)
{
    // some code
}

致电"提供/预览/ 101 /测试"看起来不错。

通过调用" offers / preview / 101"

出错
ErrorException in OfferController.php line 53:
Missing argument 2 for App\Http\Controllers\OfferController::preview()

提前谢谢。

1 个答案:

答案 0 :(得分:1)

您需要为可选参数添加默认值

public function preview($id, $string = '')
{
   // some code
}

请参阅Laravel Routing

相关问题