Reputation: 33
I have a method with two incoming arrays. The first array $columns[] contains columns names. The second one $filters[] contains search filters. How can I sort through all the values of these columns using only one search query? I can not figure out how this is done through "Eloquent". I want generate something like this:
$data::where($columns[0], '=', $filters[0])
->where($columns[1], '=', $filters[1])
...
->where($columns[n], '=', $filters[n])
Upvotes: 0
Views: 33
Reputation: 411
Try this:
$data = new Model::query();
for($i=0; $i<count($columns); $i++)
{
$data->where($columns[$i], $filter([$i]));
}
$res = $data->get();
sorry if I got your question wrong
Upvotes: 1
Reputation: 34914
You can use any loop
$query = new Model;
$count = count($columns);
for($i=0;$<$count;$i++){
$query->where($columns[$i], '=', $filters[$i]);
}
$result = $query->get();
Upvotes: 1