2015-08-24 20 views
1

小套牢參數,市場和排序傳遞可選參數是可選的不打電話來正確的

Route::get('Category/{title}/{market?}/{sort?}', '[email protected]'); 

但是,當我在URI

網址做到這一點:?類別/標題/排序= 3

它不註冊爲3排序,但在去隨着市場paramater

當然

如果URI是類別/標題/ Makert/3將返回我想要什麼

public function productList($title, $market = null, $sort = null) 
{ 
    // Gets the Categories with its Markets 
    $categorys= Product::cats(); 
    $brands = Product::CategoryWithMarket($title, $market)->groupBy('Brand')->get(); 
    $subCat = Product::where('Category', $title)->groupBy('Market')->orderBy('Market', 'ASC')->get(); 

    if (!$market) { 
     $marketList = Product::where('Category', $title)->orderBy('Brand', 'ASC')->orderBy('Label', 'ASC')->paginate(15); 
     $brands  = Product::where('Category', $title)->groupBy('Brand')->orderBy('Brand', 'ASC')->get(); 
     $mainTitle = ucfirst($title); 
    } 

    else { 
     // Gets the list of products with the catery and market attributes arranged by the brand of product 
     $marketList = Product::CategoryWithMarket($title, $market)->paginate(15); 
     $mainTitle = ucfirst($title) . ' ' . ucfirst($market) ; 
    } 

    return $sort; 

在初論應該傳回的排序參數是3,但它不返回任何東西,所以我的問題是如何獲得排序返回其值3,而不是空

回答

2

路由器只使用匹配路徑的路徑和僅路徑參數被注入到控制器。因此,如果你想排序從路由器傳遞到控制器,你需要把它放在路徑(/{sort?}),而不是在查詢(?sort = 3)。

如果你想訪問你的控制器查詢參數,您可以通過$要求做到這一點對象(如果這是你的行動的說法)或請求門面:

public function someAction() { 
    echo Request::query('sort'); 
} 
+0

哦,好的,我現在看到的感謝你這麼多 –