作为样本链接,
https://ddskart.com/product/COPIER%20TONER/NP-6/7/8000/71
如何构造GET路由?
路由必须遵循给定的格式。
Route::get('product/{category}/{model}/{product_id}', function ($category, $model, $product_id) {
// do whatever ...
});其中参数可能是
$category = 'COPIER TONER';
$model = 'NP-6/6/7/8000';
$product_id = 71;发布于 2018-10-23 08:54:34
您可以在路由中使用正则表达式约束。请参考Laravel正则表达式约束。
Route::get('product/{category}/{model}/{product_id}', function ($category, $model, $product_id) {
// do whatever ...
})->where([
'category' => '[\w\s]+',
'model' => '([a-zA-Z]+)\-(\d+)\/(\d+)\/(\d+)',
'product_id' => '[\d]+'
]);请注意,在上面的示例中,为category,model,和product_id参数提供的正则表达式与问题中给定的url匹配。你可以根据你的逻辑来调整它们。关键是,在构建复杂的路由时,可以利用Laravel正则表达式约束。
发布于 2018-10-23 08:05:51
使用urlencode()和urldecode() php函数。
https://stackoverflow.com/questions/52942348
复制相似问题