6
0
Fork 0
jiqu-library-server/app/Helpers/Paginator.php

30 lines
609 B
PHP

<?php
namespace App\Helpers;
class Paginator
{
/**
* 解析每页显示的条数
*
* @param string $perPageName
* @param int $default
* @param int|null $max
* @return int
*/
public static function resolvePerPage(string $perPageName = 'per_page', int $default = 20, ?int $max = null): int
{
$perPage = (int) request()->input($perPageName);
if ($perPage >= 1) {
if ($max !== null && $max >= 1 && $perPage >= $max) {
return $max;
}
return $perPage;
}
return $default;
}
}