For the moment, I'm working on a really poor shared hosting server, therefore I have limitations. One of my database tables increases it's records daily by about 2000. These records are basically the search results and for that I use Laravel's paginator. It has reached a point where to retrieve all of the records without getting a 500 error, I've had to remove columns from the select query.
I was wondering if there is another way to use the paginator without having to retrieve everything from the table, or if there is a more efficient way to get all the records from the table using Eloquent or the Query Builder.
Here is my code:
$results = Model::select('table.col1', 'table.col2', 'table.col3', 'table.col4',
'table.col5',
'table.col6',
'table.col7',
'table.col8',
'table.col9',
'table.col10', 'table_two.col1', 'table_three.companyName')
->leftjoin('table_three as tt', 'tt.col1', '=', 'table.col2')
->leftjoin('table_two', 'table_two.col1', '=', 'table.col1')
->where('table.col3', 2)->where('table.col11', 1)
->orderBy('col2', 'desc')
->orderBy('created_at', 'desc')->get();
$currentPage = LengthAwarePaginator::resolveCurrentPage();
$col = new Collection($final_results);
$perPage = 50;
$currentPageSearchResults = $col->slice(($currentPage - 1) * $perPage, $perPage)->all();
$entries = new LengthAwarePaginator($currentPageSearchResults, count($col), $perPage);
return $entries;
Any ideas? Or is the only way to upgrade the server?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire