Welcome Guest, Not a member yet? Register   Sign In
Query Builder "Where" with Array
#8
Smile 
(This post was last modified: 05-28-2020, 08:54 AM by IvanBell.)

I have been able to achieve desired result. It was easier than I thought actually Smile  My code looks like this now:
Code:
$this->where('catalog', $category);
unset($postFilters['page']);
foreach ($postFilters as $key => $value) {
  $this->whereIn($key, $value);
}
return $this->paginate(4)


At first I tried to use $postFilters as $key. But it didn't work because $key is an array. Then I found out that if I use $postFilters as $key => $value, the same $key becomes a string and can be used as a column name in my query.
I am also using pagination, and it appeared that page is also part of $postFilters, so I got error when tried to go to the second page. But unset($postFilters['page']) fixes that nicely.
Reply


Messages In This Thread
Query Builder "Where" with Array - by IvanBell - 05-18-2020, 02:52 AM
RE: Query Builder "Where" with Array - by akinuri - 05-19-2020, 09:20 AM
RE: Query Builder "Where" with Array - by IvanBell - 05-28-2020, 02:24 AM



Theme © iAndrew 2016 - Forum software by © MyBB