iverberk / larasearch

Searchable Eloquent Models
MIT License
225 stars 48 forks source link

Eloquent model pulls and paginate #45

Open calebsmithdev opened 9 years ago

calebsmithdev commented 9 years ago

I tried some variations to use getRecords with Eloquent and paginate, but I was unsuccessful. Has anyone tried to paginate search terms - whether through getRecords or getResults?

iverberk commented 9 years ago

Can you describe in more detail what kind of scenarios you tried and why they were unsuccessful?

calebsmithdev commented 9 years ago

Sorry for the delayed response - So I am doing a search through a database of games with the code below:

Game::search($search, ['fields' => ['game.title'=> 'text_middle']])->getRecords();

This will ultimately pull the search and show all of the results - as expected. But I am unable to paginate those results from that code directly, or add any extra chains with that code for the most part.

sebestenyb commented 9 years ago

I'd be interested in this as well, generally how to use pagination in Larasearch.

I see we can pass a limit, padding and offset as an option to the search(), but didn't dig deeper how it's plugging into the Laravel pagination.

BTW the link in the wiki (https://github.com/iverberk/larasearch/wiki/Searching#pagination) is dead.

Cheers!

aaronflorey commented 9 years ago

I did it like this

    $params['offset']  = $offset;
        $params['limit']  = $limit;
        $params['sort'][ Input::get('sort', '_score') ]['order'] = Input::get('order', 'desc');

        $results = Series::search(\Input::get('title', '*'), $params);

        $series = \Paginator::make($results->getResults()->toArray(), $results->getTotal(), $limit);
leo4all commented 9 years ago

Paginator on L5 ?

\Paginator::make no more on L5.