searchable icon indicating copy to clipboard operation
searchable copied to clipboard

Exception when I want to paginate

Open marianvlad opened this issue 9 years ago • 12 comments

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)

marianvlad avatar Apr 16 '15 15:04 marianvlad

same problem here.

mehrdd avatar Apr 17 '15 04:04 mehrdd

+1

modder2 avatar Apr 17 '15 14:04 modder2

Agreed. If you use this forked version:

https://github.com/Evertt/searchable

It works with paginate.

bryandease avatar Apr 17 '15 15:04 bryandease

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

nicolaslopezj avatar Apr 17 '15 15:04 nicolaslopezj

Make sure you are using version 1.5.2

nicolaslopezj avatar Apr 17 '15 15:04 nicolaslopezj

I am using 1.5.2. It still breaks.

bryandease avatar Apr 17 '15 17:04 bryandease

Same here, still doesn't work (1.5.3)

mydnic avatar Apr 20 '15 17:04 mydnic

@nicolaslopezj

Can you tag the version for the latest one, it must work. I think so.

gnanakeethan avatar Apr 22 '15 00:04 gnanakeethan

Still having this problem in version 1.5.14.

yugen avatar Aug 10 '15 14:08 yugen

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'));
}

herzcthu avatar Aug 12 '15 18:08 herzcthu

Paginating works for me now. I think this issue can be closed? @marianvlad

markwalet avatar Nov 14 '17 08:11 markwalet

database.php mysql strict => false

Fanxd avatar Mar 12 '19 02:03 Fanxd