You can't do it the way you want. Because the $infoList->paginate(..)
method is build in the Eloquent Model/Builder and you have the Illuminate\Database\Query\Builder
instance.
Checkout the facade from DB
.
There are multiple solutions for this. You can put the $infoList
array within a collection and use this slice
method.
$infoList = DB::connection('mysql')
->select(DB::raw('CALL dbname.GetAllUserInfo()'));
$list = collect($infoList); // or new Collection($list);
// paginate/slice the array into the set you want
// first parameter: offset, second parameter the amount/limit
$pageList = $list->slice($request->get('offset', 0), 30);
Another solution would be creating a model and don't use stored procedures (but not your required solution i guess).
class User extends Illuminate\Database\Eloquent\Model
{
// model implementation
}
$infoList = User::paginate(30); // parameter: limit/size
And another solution is too use the store procedure and do pagination in your stored procedure call:
// stored procedure
DELIMITER //
CREATE PROCEDURE GetAllUserInfo (
IN _limit smallint unsigned,
IN _offset smallint unsigned
)
BEGIN
SELECT Name, HeadOfState FROM Country
WHERE Continent = con
LIMIT _offset, _limit;
END //
DELIMITER ;
// execute the stored procedure
$infoList = DB::connection('mysql')
->select(DB::raw('CALL dbname.GetAllUserInfo('. $request->get('offset', 0) .', 30)'));
Note: its been a while I wrote a stored procedure so Im out of shape writing it. And I wrote it whats on top of my head atm.
I hope one of these solutions works out for you.