searchable
searchable copied to clipboard
Exception when I want to paginate
Hi,
I have a problem when I want to paginate search. Laravel returns
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'relevance' in 'having clause' (SQL: select count(*) as aggregate from `posts` group by `posts`.`id` having relevance > 5.25)
same problem here.
+1
Agreed. If you use this forked version:
https://github.com/Evertt/searchable
It works with paginate.
It's strange, the code is the same because @Evertt made a pull request. I will send a new update. Please update and tell if it works
Make sure you are using version 1.5.2
I am using 1.5.2. It still breaks.
Same here, still doesn't work (1.5.3)
@nicolaslopezj
Can you tag the version for the latest one, it must work. I think so.
Still having this problem in version 1.5.14.
SearchableTrait's query method is messing with pagination query. The best work around is to use custom pagination. This is method I used to search
public function searchUsers($query, $status = 1, $order_by = 'id', $sort = 'asc') {
return User::where('status', $status)->orderBy($order_by, $sort)->search($query)->get();
}
and this is method for pagination in controller
public function search() {
$query = Input::get('q');
$user = $this->users->searchUsers($query);
$total = $user->count();
$pageName = 'page';
$per_page = 20;
$page = null;
$users = new LengthAwarePaginator($user, $total, $per_page, $page, [
'path' => Paginator::resolveCurrentPath(),
'pageName' => $pageName,
]);
return view('index', compact('users'));
}
Paginating works for me now. I think this issue can be closed? @marianvlad
database.php mysql strict => false