{"id":18796030,"url":"https://github.com/dees040/pagination","last_synced_at":"2025-08-22T07:16:42.705Z","repository":{"id":56964714,"uuid":"125525930","full_name":"dees040/pagination","owner":"dees040","description":"Dynamic pagination in Laravel","archived":false,"fork":false,"pushed_at":"2018-03-20T14:08:34.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-29T16:57:34.417Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dees040.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-16T14:18:11.000Z","updated_at":"2018-03-20T14:08:35.000Z","dependencies_parsed_at":"2022-08-21T09:20:34.588Z","dependency_job_id":null,"html_url":"https://github.com/dees040/pagination","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dees040%2Fpagination","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dees040%2Fpagination/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dees040%2Fpagination/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dees040%2Fpagination/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dees040","download_url":"https://codeload.github.com/dees040/pagination/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239720526,"owners_count":19686117,"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":[],"created_at":"2024-11-07T21:36:12.823Z","updated_at":"2025-02-19T19:26:49.125Z","avatar_url":"https://github.com/dees040.png","language":"PHP","readme":"# Dynamic pagination in Laravel\n\n\u003ca href=\"https://packagist.org/packages/dees040/pagination\"\u003e\u003cimg src=\"https://poser.pugx.org/dees040/pagination/v/stable\" alt=\"Latest Stable Version\"\u003e\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/dees040/pagination\"\u003e\u003cimg src=\"https://poser.pugx.org/dees040/pagination/downloads\" alt=\"Total Downloads\"\u003e\u003c/a\u003e\n\u003ca href=\"https://travis-ci.org/dees040/pagination\"\u003e\u003cimg src=\"https://travis-ci.org/dees040/pagination.svg?branch=master\" alt=\"Build status\"\u003e\u003c/a\u003e\n\nDynamic pagination for your Eloquent models. Paginate, order and sort with just the query parameters. \n\n## Installation\n\nUse composer to install the package.\n\n```bash\ncomposer require dees040/pagination\n```\n\nThe service provider will automatically by registered using Laravel 5.5 or higher. Otherwise add the following provider to your `providers` array in the `config/app.php`\n\n```php\ndees040\\Pagination\\ServiceProvider\n``` \n\nThe package comes with a small config file. To publish the config file run the following command:\n\n```bash\nphp artisan vendor:publish --provider=\"dees040\\Pagination\\ServiceProvider\" --tag=\"config\"\n```\n\n## Usage\n\nThe package will add a macro (method) to the Eloquent builder automatically when the service provider is registered. You can then use the `dynamicPagination()` method. If you like you can chance the method name in the config.\n\nExample:\n\n```php\n\u003c?php\n\nnamespace App\\Http\\Controllers;\n\nuse App\\User;\n\nclass UserController extends Controller\n{\n    public function index()\n    {\n        $users = User::where('age', '\u003e', 18)\n            -\u003edynamicPagination();\n        \n        return response()-\u003ejson($users);\n    }\n}\n\n``` \n\nThe `dynamicPagination()` has the same signature as the [`paginate()`](https://laravel.com/api/5.6/Illuminate/Database/Eloquent/Builder.html#method_paginate) method from the Eloquent builder:\n\n```php\ndynamicPagination($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)`\n```\n\nAll these parameters are optional and if some are not given it will try and read them from the query (GET) parameters.\n\n### Parameter options\n\n**`page`**\n\nThe page parameter is the main parameter. If the `page` parameter is not present in the query (GET) parameters the results will not be paginated. Unless the config value `force_pagination` is set to `true`. The page parameters represents the page which needs to be paginated.\n\n**`per_page`**\n\nThe per page parameter represents the amount of items that needs to be paginated per page. So if the value is 15, the paginator will return 15 results. If the parameter is not found, the paginator will use the [default value](https://github.com/laravel/framework/blob/5.6/src/Illuminate/Database/Eloquent/Model.php#L83) set in the model, which can be overwritten in the model.\n\n**`order_by`**\n\nIf you'd like you can execute an `order by` before you paginate the results. This comes in handy if you are using an API and you can order the results in a table in your frontend application. The paginator checks if you can use the given key for ordering. It checks if the method `getOrderableKeys()` exists in the model. This method should return an array of fields (strings) which can be orderd on. If the `getOrderableKeys()` doesn't exists it will use the `$fillable` items. The `id` key will always be added. \n\n**`sort_by`**\n\nIn what way do you want to your results to be ordered? `asc` or `desc`? Specify it with this parameter option. This can only be used with the `order_by` parameter.\n\n#### Example route\n\nAn example if all parameters are used:\n\n`https://example.com/posts?page=3\u0026per_page=30\u0026order_by=updated_at\u0026sort_by=desc`\n\nHere you will get 30 posts starting on page 3. The results are ordered by the `updated_at` field, descending.\n\n## TODO\n\n- Order by relations\n- Add options to search\n  - Using scout\n- Add support with macros\n  - For collections\n  - For Query Builder\n- Order by multiple fields","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdees040%2Fpagination","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdees040%2Fpagination","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdees040%2Fpagination/lists"}