Skip to content

Pagination

All list endpoints return paginated results using Laravel's offset-based pagination.

Request Parameters

ParameterTypeDefaultDescription
pageinteger1Page number
perPageinteger15Items per page
searchstringnullSearch term
sortFieldstringvariesField to sort by
sortDirectionstringascSort direction (asc or desc)

Example Request

http
GET /api/v1/patients?page=2&perPage=20&search=dela+cruz&sortField=last_name&sortDirection=asc
Authorization: Bearer {token}
X-Branch-Id: 1

Response Format

json
{
  "data": [
    {
      "id": 21,
      "pin": "MAIN-000021",
      "first_name": "Juan",
      "last_name": "Dela Cruz"
    }
  ],
  "links": {
    "first": "http://localhost:8000/api/v1/patients?page=1",
    "last": "http://localhost:8000/api/v1/patients?page=4",
    "prev": "http://localhost:8000/api/v1/patients?page=1",
    "next": "http://localhost:8000/api/v1/patients?page=3"
  },
  "meta": {
    "current_page": 2,
    "from": 21,
    "last_page": 4,
    "per_page": 20,
    "to": 40,
    "total": 72
  }
}

How It Works

Pagination is handled by AbstractFilterableRepository::getPaginated():

php
$results = $repository->getPaginated(
    search: $request->input('search'),
    filters: $request->only(['sortField', 'sortDirection', ...]),
    perPage: $request->input('perPage', 15)
);

Each repository defines:

  • Allowed sort fields — validated against a whitelist to prevent SQL injection
  • Default sort field — used when no sort is specified
  • Custom filters — model-specific query scopes (gender, status, date range, etc.)

Filtering

Some endpoints support additional filter parameters:

Patients

?search=john                    # Search by name
?filters[sex]=male              # Filter by gender
?filters[civil_status]=single   # Filter by civil status
?filters[status]=active         # Filter by status

Transactions

?search=TRX-123                 # Search by transaction number
?start_date=2026-01-01          # Filter by date range
?end_date=2026-03-31
?status=Completed               # Filter by status

CPR - Clinical Patient Records