I using third party. I get from here : https://github.com/andersao/l5-repository
My function in file repository is like this :
public function displayList($year, $id = NULL)
{
$clauses = ['year' => $year];
if(isset($id)) {
$clauses = array_merge($clauses, ['id' => $id]);
}
$query = Self::orderBy('programcode')
->orderBy('accountcode')
->findWhere($clauses)
->paginate(1);
return $query;
}
When executed, there exist error like this : Method paginate does not exist.
.
I try remove ->findWhere($clauses)
. It works. No error.
Findwhere and paginate apparently can not run simultaneously
Is there a solution to this problem?
It is because ->findWhere(...)
ends the query with ->get()
and returns the results (eloquent collection).
What you're trying to do is calling a ->paginate(...)
method on an eloquent collection. It is actually a method on query builder.
Solution
$query = Self::orderBy('programcode')
->orderBy('accountcode')
->applyConditions($clauses)
->paginate(1);
Edit
Okay, so ->applyCondtions()
does not return the object so you can't chain methods off of it. Try this:
$query = Self::orderBy('programcode')
->orderBy('accountcode');
$query->applyConditions($clauses);
$query = $query->paginate(1);
Like this:
$list = $this->repository->scopeQuery(function($query) use ($filterColumns) {
return $query->where($filterColumns)->orderBy('created_at', 'DESC');
});
$list->paginate(10);