Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can´t paginate while using fence #5

Open
Moyhdez opened this issue Feb 21, 2018 · 2 comments
Open

Can´t paginate while using fence #5

Moyhdez opened this issue Feb 21, 2018 · 2 comments

Comments

@Moyhdez
Copy link

Moyhdez commented Feb 21, 2018

When i try to paginate using scopeFence i get this error:

(2/2) QueryException
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'distance' in 'having clause' (SQL: select count(*) as aggregate from spots inner join favorites on spots.id = favorites.spot_id where favorites.user_id = 1 having distance BETWEEN 0 AND 150)

@YavorK
Copy link

YavorK commented Mar 21, 2018

Yes, same with the other method, but you can do it with the query builder...
DISCLAIMER: did not try it with the fence method but should be VERY similar.

public function index(Request $request)
  $requestPage = $request->input('page') ?? 1; // rewrite to $request->input('page') !== null ?  $request->input('page') : 1;  for older PHP versions
  $resultsPerPage = 30;
  $places = Place::distance($lat, $lng)
    ->orderBy('distance', 'ASC')
    ->skip(($requestPage - 1) * $resultsPerPage)
    ->take($resultsPerPage)
    ->get();
  return $places;
}

@veneliniliev
Copy link

check this package https://github.com/justbetter/laravel-pagination-with-havings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants