{"id":18870410,"url":"https://github.com/sebastiansulinski/php-paginator","last_synced_at":"2025-07-14T04:40:26.437Z","repository":{"id":57323229,"uuid":"106719283","full_name":"sebastiansulinski/php-paginator","owner":"sebastiansulinski","description":"Framework agnostic PHP Pagination component","archived":false,"fork":false,"pushed_at":"2024-03-19T15:48:10.000Z","size":723,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-28T08:21:52.743Z","etag":null,"topics":["paginate","paginate-array","paginate-collection","paginated-posts","pagination","paginator","php-pagination"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sebastiansulinski.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-10-12T16:40:13.000Z","updated_at":"2023-06-06T11:04:57.000Z","dependencies_parsed_at":"2024-09-18T20:47:46.602Z","dependency_job_id":"2d04e975-711c-4f43-86f3-6a0263bbc96f","html_url":"https://github.com/sebastiansulinski/php-paginator","commit_stats":{"total_commits":54,"total_committers":6,"mean_commits":9.0,"dds":0.6851851851851851,"last_synced_commit":"844c75046af46ae65955babce422ec4cb74b42ff"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebastiansulinski%2Fphp-paginator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebastiansulinski%2Fphp-paginator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebastiansulinski%2Fphp-paginator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebastiansulinski%2Fphp-paginator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sebastiansulinski","download_url":"https://codeload.github.com/sebastiansulinski/php-paginator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223635066,"owners_count":17177075,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["paginate","paginate-array","paginate-collection","paginated-posts","pagination","paginator","php-pagination"],"created_at":"2024-11-08T05:20:03.642Z","updated_at":"2024-11-08T05:20:05.125Z","avatar_url":"https://github.com/sebastiansulinski.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Framework agnostic PHP Pagination component\n\nLight weight, easy drop-in pagination component for PHP 8 applications.\n\n### Installation\n\n```\ncomposer require sebastiansulinski/php-paginator\n```\n\n### Structure\n\nThe component consist of 2 main classes:\n\n* `Pagination` - class, to which you pass\n    * instance of a `SSD\\Paginator\\Request` or, if your project already makes use of `\\Illuminate\\Http\\Request`, you can pass instance of it instead.\n    * total number of records\n    * number of records per page\n    * string key representing the query string parameter associated with the current page\n    \n* `Paginator` - a parent class for any implementations that return the html structure of a pagination. Its constructor takes 2 arguments:\n\n    * instance of `Pagination`\n    * records for a given page as instance of `SSD\\Paginator\\Collection` or `Illuminate\\Support\\Collection`\n \nPackage comes with one implementation of `Paginator`:\n\n#### VueSelectPaginator\n\nThe `VueSelectPaginator` returns the following structure when `render()` method is called on its instance (all entities are decoded for clarity):\n\n```\n\u003cssd-paginator \n    :options=\"{\n        \"1\":\"http://paginator.app\",\n        \"2\":\"http://paginator.app/?page=2\",\n        \"3\":\"http://paginator.app/?page=3\",\n        \"4\":\"http://paginator.app/?page=4\",\n        \"5\":\"http://paginator.app/?page=5\"\n    }\" \n    current=\"http://paginator.app/?page=2\" \n    previous=\"http://paginator.app\" \n    next=\"http://paginator.app/?page=3\" \n    first=\"http://paginator.app\" \n    last=\"http://paginator.app/?page=5\" \n    :number-of-pages=\"5\"\n\u003e\u003c/ssd-paginator\u003e\n```\n\nAnd to support this implementation, there is a `VueJs` component that ships with this package - you'll find it under `resources/src/js/components/SsdPaginator`:\n\n```javascript\nimport { createApp } from 'vue'\nimport SsdPaginator from './components/SsdPaginator'\n\ncreateApp({\n  components: { SsdPaginator },\n}).mount('#app')\n```\nTo create your own implementations of `Paginator` all you have to do is to provide implementation of the `html()` method, which should return the html structure of your pagination layout.\n\n### Styling\n\nSsdPaginator comes pre-formatted using tailwindcss v3, but you can replace its structure using the available slot and apply your own styling as required.\n\n### Usage\n\n```php\n// import all dependencies\n\nuse SSD\\Paginator\\Request;\nuse SSD\\Paginator\\Collection;\nuse SSD\\Paginator\\Pagination;\nuse SSD\\Paginator\\VueSelectPaginator;\n\n// instantiate Pagination class\n\n$pagination = new Pagination(\n    Request::capture(),\n    160,\n    10,\n    'page'\n);\n\n// get your records as array and pass through to the Collection\n// in this example I just use array of numbers and get only a chunk\n// of records based on offset and limit, but you'd probably use\n// some active model to get only the records you're after\n\n$records = range(1, 160);\n$records = new Collection($records);\n\n$chunk = $records-\u003esplice(\n    $pagination-\u003eoffset(),\n    $pagination-\u003elimit()\n);\n\n// instantiate SelectPaginator with instance of Pagination and collection of records\n\n$paginator = new VueSelectPaginator($pagination, $chunk);\n```\n\n### Displaying records and pagination\n\n```php\n// loop through records using Collection::map() and implode() methods\n\necho $paginator-\u003erecords()-\u003emap(function($record) {\n    // ... \n})-\u003eimplode('');\n\n// or using standard foreach loop\n\nforeach($paginator-\u003erecords() as $record) {\n    // ...\n}\n\n// display pagination\n\necho $paginator-\u003erender();\n```\n\n### Custom pagination structure\n\nIf you don't want to use `Paginator` class implementation, the `Pagination` class has all necessary methods to allow you put together pagination structure directly in your view, for instance to display list of all pages as clickable numbers with current page highlighted using `class=\"active\"`, you could do something like:\n\n```php\n$pagination = new Pagination(\n    Request::capture(),\n    160,\n    10,\n    'page'\n);\n\necho '\u003cul\u003e';\n\necho $pagination-\u003eurlList()-\u003emap(function(string $url, int $page) use($pagination) {\n    $link  = '\u003cli\u003e\u003ca href=\"'.$url.'\"';\n    $link .= $pagination-\u003ecurrent() === $page ? ' class=\"active\"' : null;\n    $link .= '\u003e'.$page.'\u003c/a\u003e\u003c/li\u003e';\n    return $link;\n})-\u003eimplode('');\n\necho '\u003c/ul\u003e';\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsebastiansulinski%2Fphp-paginator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsebastiansulinski%2Fphp-paginator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsebastiansulinski%2Fphp-paginator/lists"}