2017-01-07 38 views
0

我有這樣的方法:php - 地址中的布爾參數,如何傳遞給方法?

public function getAll($name = false, $json = false) { 

    if ($name) 
     $sections = Sections::all()->pluck('name'); 
      else 
       $sections = Sections::all(); 


    return ($json) ? json_encode($sections) : $sections; 
} 

和地址是這樣的:example.com/api/sections/all/{name}/{json}
所以,我對於這個問題 - 如何爲TRUE參數定義的地址?
在我看來example.com/api/sections/all/true/true是不好的主意,因爲我顯示參數類型。
你提出了什麼解決方案?或者也許另一種方法建設?

回答

0

這似乎是合理的有namejsonquery parameters,所以你的URL變得像example.com/api/sections/all?name=1&json=1

相關問題