我有一个选择这个选项:
<select id="bairro" name="bairro" class="sg-form--control">
<option value="all">All</option>
<option value="1">Centro</option>
<option value="2">Anhumas</option>
<option value="3">São José</option>
</select>
以下控制器:
public function filterIlumination($neighborhood) {
$lampModels = LampModels::all()->toArray();
$aluminumcableModels = AluminumcableModels::all()->toArray();
$reactorModels = ReactorModels::all()->toArray();
$steelconduitModels = SteelconduitModels::all()->toArray();
$ilumination = Ilumination::whereRaw('street_neighborhood_id = ?', array($neighborhood))
->with('street')
->with('neighborhood')
->with('reactor')
->with('steelconduit')
->with('aluminumcable')
->with('economyplan')
->with('lamp')->get();
return Response::json(array('ilumination' => $ilumination,
'lampModels' => $lampModels,
'aluminumcableModels' => $aluminumcableModels,
'steelconduitModels' => $steelconduitModels,
'reactorModels' => $reactorModels));
}
我认为条件似乎(邻居=='全部')是过滤所有,但我有很多其他选项,我不是那么聪明的想法。我检查了Laravel的文档,我还没有找到它。如果有人可以帮我这个,我不知道我做了什么。
答案 0 :(得分:0)
您可以使用空字符串作为邻域的值:
<select id="bairro" name="bairro" class="sg-form--control">
<option value="">All</option>
<option value="1">Centro</option>
<option value="2">Anhumas</option>
<option value="3">São José</option>
</select>
如果$ neighborhood不为空,则仅添加WHERE条件。