I want to paginate a custom static function.
When using Eloquent goes like this People::paginate(5);
and paginates the results.
I need to do the same for this static function People::getOwners();
I want to paginate a custom static function.
When using Eloquent goes like this People::paginate(5);
and paginates the results.
I need to do the same for this static function People::getOwners();
Just do your query and pagination in the function, like this:
public function getOwners() {
return self::query()->paginate(5);
}
Depending on what is going on inside getOwners()
, you could turn it into a query scope. On your People
model, add the function:
public function scopeGetOwners($query) {
// $query->where(...);
// $query->orderBy(...);
// etc.
$return $query;
}
Now, getOwners()
is treated like any other query scope modifier (e.g. where, orderBy, etc.):
People::getOwners()->paginate(5);