2
我有一個購物車,我希望能夠傳遞可變數量的可選參數。喜歡的東西:排序,篩選通過,包含/排除等,所以該URL可能是:Laravel 4中可以有可變數量的URI參數或鍵值對嗎?
/products
/products/sort/alphabetically
/products/filter/cloths
/products/socks/true
/products/sort/alphabetically/socks/true/hats/false/
等等
我想我可以有佔位符的路線爲所有可能的參數和設置在URL中的默認值,所以是這樣的:
Route::get('products/sort/{$sort?}/filter/{$filter?}/socks/{$socks?}/hats/{$hats?}/...', function($sort = 'alphabetically', $filter = false, $socks = true, $hats = true, ...)
{
...
});
然後例如只排除帽子我必須有一個網址爲:
/products/sort/alphabetically/filter/false/socks/true/hats/false
但這似乎真的很不雅。有沒有這樣做的好方法? 我想我也可以嘗試編寫一個服務器重寫規則來說明這一點,但我不喜歡規避Laravel的想法。
是的,這就是我最終做的。儘管如此,謝謝你的回答! – Beau