laravel 5.1中的路由参数

时间:2015-10-15 08:58:39

标签: php laravel laravel-5 laravel-routing

我知道如何在路由约束上使用正则表达式,但我想使用固定值而不是像这样的正则表达式:

Route::get('{param}/delete/{id}',array(
    'as'    => 'delete-post',
    'uses'  => 'MainController@delete'
))->where(['param',['post','page'],'id'=>'[0-9]+']);

当我尝试这个时,我收到的错误就像是Routing requirement for "param" must be a string.

我想要的是param参数的值是固定的,它应该是postpage。那么,我怎样才能实现上述目标呢?

1 个答案:

答案 0 :(得分:0)

您可以使用正则表达式:

Route::get('{param}/delete/{id}',array(
    'as'    => 'delete-post',
    'uses'  => 'MainController@delete'
))->where(['param' => 'post|page', 'id'=>'[0-9]+']);