Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel using paginate() with select() method

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

like image 820
SomeRandomDude Avatar asked Nov 02 '22 07:11

SomeRandomDude


2 Answers

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

like image 83
Vladislav Rastrusny Avatar answered Nov 07 '22 21:11

Vladislav Rastrusny


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);
like image 38
Arbitur Avatar answered Nov 07 '22 22:11

Arbitur