generated from liutk/owl-admin-base
30 lines
612 B
PHP
30 lines
612 B
PHP
<?php
|
|
|
|
namespace App\Traits;
|
|
|
|
trait PaginatorTrait
|
|
{
|
|
/**
|
|
* 解析每页显示的条数
|
|
*
|
|
* @param string $perPageName
|
|
* @param int $default
|
|
* @param int|null $max
|
|
* @return int
|
|
*/
|
|
public 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;
|
|
}
|
|
}
|