I create an extension called material
and everything works fine. I want to implement simple search query, so I sampled it from bixie/portfolio
extension which you can get it from marketplace
. So I have this code in my MaterialController
:
$user_id = App::user()->id;
$query = array_values(Material::query()->where('user_id = ?', [$user_id])->get());
$filter = array_merge(array_fill_keys(['search', 'order', 'limit'], ''), $filter);
extract($filter, EXTR_SKIP);
if ($search) {
$query->where(function ($query) use ($search) { //<-- this throw error.
$query->orWhere(['name LIKE :search'], ['search' => "%{$search}%"]);
});
}
and I will get fatal error:
Fatal error: Call to a member function where() on array in line...
What do the error mean?
I googled a bit and some comment that function where() need to use with collections. How can I resolve it in this case?
I am using pagekit 1.0.12
, symfony ~3.0.0
.