Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions src/Database/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1558,12 +1558,12 @@ public function drop(): bool
/**
* Paginate, make pagination system
*
* @param int $number_of_page
* @param int $per_page
* @param int $current
* @param int $chunk
* @return Pagination
*/
public function paginate(int $number_of_page, int $current = 0, ?int $chunk = null): Pagination
public function paginate(int $per_page, int $current = 0, ?int $chunk = null): Pagination
{
// We go to back page
--$current;
Expand All @@ -1573,7 +1573,7 @@ public function paginate(int $number_of_page, int $current = 0, ?int $chunk = nu
$jump = 0;
$current = 1;
} else {
$jump = $number_of_page * $current;
$jump = $per_page * $current;
$current++;
}

Expand All @@ -1582,7 +1582,7 @@ public function paginate(int $number_of_page, int $current = 0, ?int $chunk = nu
$join = $this->join;
$data_bind = $this->where_data_binding;

$data = $this->jump($jump)->take($number_of_page)->get();
$data = $this->jump($jump)->take($per_page)->get();

if (is_array($data)) {
$data = collect($data);
Expand All @@ -1594,7 +1594,9 @@ public function paginate(int $number_of_page, int $current = 0, ?int $chunk = nu
$this->where_data_binding = $data_bind;

// We count the number of pages that remain
$rest_of_page = ceil($this->count() / $number_of_page) - $current;
$total = $this->count();
$total_of_page = (int) ceil($total / $per_page);
$rest_of_page = $total_of_page - $current;

// Grouped data
if (is_int($chunk)) {
Expand All @@ -1603,12 +1605,12 @@ public function paginate(int $number_of_page, int $current = 0, ?int $chunk = nu

// Enables automatic paging.
return new Pagination(
$current >= 1 && $rest_of_page > 0 ? $current + 1 : 0,
($current - 1) <= 0 ? 1 : ($current - 1),
(int)($rest_of_page + $current),
$number_of_page,
$current,
$data
next: $current >= 1 && $rest_of_page > 0 ? $current + 1 : 0,
previous: ($current - 1) <= 0 ? 1 : ($current - 1),
total: $total,
perPage: $per_page,
current: $current,
data: $data,
);
}

Expand Down
Loading