如何在laravel 5中处理多个参数的破折号路由


How to handle dashes route in laravel 5 for multiple parameter

这是我的url结构

http://example.com/embed-id-size

http://example.com/embed adsdfwer3 - 640 x240

其中size为可选参数。

我在laravel 5的routes.php中这样编码。

Route::any('embed-{id}-{size?}',['uses'=>'Example@video','as'=>'embed']);

以上工作都很好,没有问题,但问题来了,当我的id已经像这样划了adsdfw-r3

http://example.com/embed adsdfw - r3 - 640 x240http://example.com/embed-adsdfw-r3

上面的url laravel route not working和route假设有三个参数。

经过多次搜索,我发现这个->where('id', '.*(?=-)'),我把它应用到我的路由,它的工作很好,只有当我给我的url大小,但大小是一个可选的参数后,应用->where('id', '.*(?=-)')大小成为强制性的。

请告诉我如何解决这个问题。

我希望你能理解我的问题

要解决这个问题并不容易,因为id中的破折号。

我要么确保没有破折号,要么捕获整个{id}-{size?}并稍后计算是否最终有分辨率,哪一个是id。