2
I would like to know how to filter my data from the database with a form where it contains more than 1 field to filter, I could only do with one field.
Form:
<form action="{{ url('panel/brands') }}" method="GET" name="frm_filter_brand" role="search">
<div class="row ls-clearfix">
<div class="ls-box-filter">
<div class="row ls-clearfix">
<div class="col-md-3">
<label class="ls-label">
<b class="ls-label-text">ID</b>
<div class="ls-field-md">
<input class="uppercase" name="id" id="id" placeholder="Ex.: 10" type="text" value="">
</div>
</label>
</div>
<div class="col-md-3">
<label class="ls-label">
<b class="ls-label-text">Nome</b>
<div class="ls-field-md">
<input class="uppercase" name="name" id="name" placeholder="Ex.: FORD" type="text" value="">
</div>
</label>
</div>
<div class="col-md-3">
<label class="ls-label">
<b class="ls-label-text">Descrição</b>
<div class="ls-field-md">
<input class="uppercase" name="description" id="description" placeholder="Ex.: Novas" type="text" value="">
</div>
</label>
</div>
<div class="">
<label style="margin-top:16px" class="ls-label ls-float-right">
<label class="ls-label">
<button id="btn-filter" type="submit" class="ls-btn ls-btn-filtrar">Filtrar</button>
</label>
</label>
</div>
</div>
</div>
</div>
</form>
My controller:
public function index(Request $request)
{
$filter_id = $request->id;
if($filter_id){
$brands = $this->brand::where('id', $filter_id)->get();
}else{
$brands = $this->brand::all();
}
return view('brand.index', compact('brands'));
}
So I would like to check which values I entered in the filters and do the search with the same.
You want to create more than one condition with the
where
using the form inputs, that’s it?– bio
That’s right, but the way you indicated, if I filter only by "ID" will not enter the right condition? if($filter_id && $filter_name && $filter_description){
– Renne Galli
The idea is that you have the three variables to do the
where
correctly. For this reason I modified the condition. Variables may come empty?– bio
yes can, I think the case would be: -receive the form -verify which were entered -perform the search only with the informed ones
– Renne Galli
I altered, check if it works...
– bio
very well, it worked perfectly, thanks for the bio help! abç
– Renne Galli