Skip to content

Pagination

Tirapong Chaiyakun edited this page Sep 19, 2026 · 1 revision

Pagination

รองรับ ?page=1&per_page=15
per_page สูงสุด 100

จาก controller

public function index(): never
{
    $this->paginate(\App\Models\User::class);
}

public function active(): never
{
    $this->paginate(\App\Models\User::class, ['status' => 'active']);
}

$where เป็นการเทียบค่าตรงกัน ไม่ใช่ค้นข้อความ ?q=

ตอบเอง

[$page, $perPage] = \Core\Paginator::fromRequest($this->request);
$result = \App\Models\User::paginate($page, $perPage);
\Core\Response::paginate($result['data'], $result['total'], $page, $perPage);

รูปแบบ meta

{
  "meta": {
    "pagination": {
      "total": 23,
      "per_page": 10,
      "current_page": 2,
      "last_page": 3,
      "from": 11,
      "to": 20
    }
  }
}

ถ้าไม่มีแถว from และ to เป็น 0

Clone this wiki locally