What errors are you getting?
Jan 19, 2018
6
Level 1
Pagination not working
I am trying to fetch few records from DB and applying pagination on results but pagination seems not to be working. Here is my code snippet:
Class City {
public function ads() {
return $this->hasManyThrough('Sello\Ad', 'Sello\User');
}
}
public function getAdsFeedWithFilters(Request $request) {
// fetch request params
$ads = $city->load(['ads' => function($query) use (
$termsRS,
$checkForSearchTerm,
$checkForPostedWithin, $checkForPriceRange,
$sortByColumn, $sortOrder, $postedWithin, $priceEndRange, $priceStartRange) {
$query->where('status', '=', Ad::$STATUS_DRAFT);
if ($checkForPriceRange) {
$query->where('price', '>=', $priceStartRange);
$query->where('price', '<=', $priceEndRange);
}
if ($checkForPostedWithin) {
$query->whereRaw('creation_date >= NOW() - INTERVAL ' . $postedWithin . ' DAY');
}
if ($checkForSearchTerm) {
$query->whereRaw("MATCH (title) AGAINST (?)", [$termsRS]);
}
$query->orderBy($sortByColumn, $sortOrder);
$query->paginate(Ad::$ADS_PER_PAGE);
}]);
// return results
return ResponseFormatter::format($code, $message, $ads);
}
I get the required results but result object does not contains fields like pageNo, totalPages, Next and Previous page urls etc.
Please or to participate in this conversation.