3
I am trying to use the manual paging of Laravel 5.1 because I have a query that needs to be written with the DB select, but the paging does not work! It returns me all the data on the screen without paging.
Follows:
use Illuminate\Pagination\LengthAwarePaginator as Paginator;
$my_query = DB::select('
;WITH
UL1 As (SELECT E.ClientStoreID, MAX(E.InsertDate) AS data
FROM ClientStoreMediaExecuted AS E, ClientStore AS S
WHERE E.ClientStoreID = E.ClientStoreID
AND S.ClientID=?
GROUP BY E.ClientStoreID)
SELECT CS.* FROM UL1 RIGHT OUTER JOIN ClientStore AS CS
ON (CS.ClientStoreID = UL1.ClientStoreID)
WHERE CS.ClientID=?
AND CS.IsActive=1', [$id, $id]);
$paginator = new Paginator($my_query, count($my_query), $perPage, $currentPage, [
'path' => Request::path(),
'query' => $my_query,
'fragment' => array_slice($my_query, $perPage),
'pageName' => 'page'
]);
You cannot use the function
paginate()
of Laravel ?– Diego Souza
I can’t use it. Laravel’s paginate() function only works when the query has no group by and also does not work with DB::select only with DB::table and Eloquent. I will edit the question and put the query.
– Tais
What is the value of the variable
$perPage
?– Diego Souza
the value is 20 per page.
– Tais