6

Is it possible to use paginate() with the select() method? Using the code below I get the error:

Call to a member function paginate() on a non-object

$query = 'SELECT * FROM items';
$results = DB::select($query)->paginate(10);

I know the following code works with paginate() with just the table() method:

$results = DB::table('plans_shared')->paginate(10);

It seems much easier for me to use the select() since I have many conditional AND/WHERE clauses

3 Answers 3

1

select() method returns array so paginate() cannot be called on it. You can only try to use \Paginator::make(DB::select($query)) if you like

Sign up to request clarification or add additional context in comments.

Comments

1

If you have an array and want to paginate it use Paginate::make() Paginate Laravel 4.2

Ex:

$pages = Paginate::make(DB::select($query), 10);

1 Comment

What about Laravel 5?
-1

$items = DB::table('team')
->selectRaw('SELECT *,earth_distance(ll_to_earth(team.lat, team.lng), ll_to_earth(23.1215939329,113.3096030895)) AS distance') ->whereRaw('earth_box(ll_to_earth(23.1215939329,113.3096030895),1000) @> ll_to_earth(team.lat, team.lng)') ->paginate(10);

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.