我知道Laravel支持使用正则表达式进行路由,如下所示
Route::get('user/{id}', function($id) {
//
})
->where('id', '[0-9]+');
如果我的端点喜欢 / {size} / photo ,例如 /100x100/foo.jpg 如何使用正则表达式检查大小是否有效?
我是regex的新手。感谢
答案 0 :(得分:0)
Route::get('{size}/{filename}.jpg', function($size, $filename) {
list($width, $height) = explode('x', $size);
// Now use $width and $height, and enjoy life!
})
->where('size', '\d+x\d+');