{"id":36978802,"url":"https://github.com/thoss/laravel-gap-sort","last_synced_at":"2026-01-13T22:48:19.975Z","repository":{"id":154534372,"uuid":"631872444","full_name":"thoss/laravel-gap-sort","owner":"thoss","description":"Sortable behaviour for Eloquent models with gap algorithm","archived":false,"fork":false,"pushed_at":"2023-05-05T07:32:54.000Z","size":157,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-13T14:39:36.536Z","etag":null,"topics":["eloquent","gap","laravel","performant","php","sort","trait"],"latest_commit_sha":null,"homepage":"","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/thoss.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}},"created_at":"2023-04-24T08:37:01.000Z","updated_at":"2023-04-26T14:06:40.000Z","dependencies_parsed_at":"2023-07-11T07:33:14.019Z","dependency_job_id":null,"html_url":"https://github.com/thoss/laravel-gap-sort","commit_stats":{"total_commits":86,"total_committers":2,"mean_commits":43.0,"dds":"0.023255813953488413","last_synced_commit":"7b6c000bee085abf631644a9fb5855bca5e102ed"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/thoss/laravel-gap-sort","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoss%2Flaravel-gap-sort","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoss%2Flaravel-gap-sort/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoss%2Flaravel-gap-sort/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoss%2Flaravel-gap-sort/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thoss","download_url":"https://codeload.github.com/thoss/laravel-gap-sort/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoss%2Flaravel-gap-sort/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28403726,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T14:36:09.778Z","status":"ssl_error","status_checked_at":"2026-01-13T14:35:19.697Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["eloquent","gap","laravel","performant","php","sort","trait"],"created_at":"2026-01-13T22:48:19.328Z","updated_at":"2026-01-13T22:48:19.970Z","avatar_url":"https://github.com/thoss.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sortable behaviour for Eloquent models with gap algorithm\n\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)\n![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/thoss/laravel-gap-sort/run-tests.yml?branch=main\u0026label=tests)\n![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/thoss/laravel-gap-sort/phpstan.yml?branch=main\u0026label=PHPStan)\n[![Latest Version](https://img.shields.io/github/v/release/thoss/laravel-gap-sort.svg?style=flat-square)](https://github.com/thoss/laravel-gap-sort/releases)\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/thoss/laravel-gap-sort.svg?style=flat-square)](https://packagist.org/packages/thoss/laravel-gap-sort)\n\nThis package provides a way to sort items in a table using the \"Gap\" algorithm, which is a more efficient way of reordering items in a table than using incremental values. It takes into account the gap between the order values of adjacent items and calculates the new order value for the main item based on the positions of the previous and next items.   \n    \nSo you can sort an item to any position with just one operation, you don't have to change other items!\n\n[Description of the class Thoss\\GapSort\\SortModel](SORTMODEL_DESCRIPTION.md)\n\n## Requirement\n\n- PHP 8.1\n- Laravel 9/10\n- Your order column must be an integer (recommended is unsigned integer)\n\n## Installation\n\nYou can install this package using composer.  \nJust run the command below.\n\n```\ncomposer require thoss/laravel-gap-sort\n```\n\n\nOptionally you can publish the config file with:\n\n```bash\nphp artisan vendor:publish --tag=gap-sort-config\n```\n\nThis is the content of the file that will be published in `config/gap-sort.php`\n\n```php\nreturn [\n    /*\n    * The name of the column that will be used to sort models.\n    */\n    'order_column' =\u003e 'order',\n\n    /*\n    * The gap between the sorted items\n    */\n    'order_gap' =\u003e 1000,\n\n    /*\n    * Indicates wheter the \"/sort\" route will be automaticaly added when you use the route ::register method\n    */\n    'resource_registrar_with_sort' =\u003e false,\n];\n\n```\n\n\n## Usage\n\nTo add sortable behaviour to your model you must:\n\n1. Use the trait `Thoss\\GapSort\\Traits\\Sortable` in your Model.\n2. Optionally specify which column will be used as the order column. The default is `order_column`.\n3. Optionally specify which gap between the sorted items you want to use. The default is `order_gap`.\n\n\u003e The larger the gap, the lower the probability that the table will have to be reinitialized\n\n4. You can initialize an existing Table with the order gap, maybe in a Migration file\n\n```php\ndispatch(new SortModel(modelString: YourModel::class, initTable:true));\n```\n\n### Use the sorting with an REST API\n\n1. register `/sort` Route  \n(with the enabled resource registrar you can easily add the `/sort` Route)\n```php\nRoute::resource('salutations', 'SalutationsController', ['with' =\u003e ['sort']]);\n```\n2. Dispatch  the `SortModel` Job in your Controller\n\n```php\nuse Thoss\\GapSort\\Requests\\SortRequest;\nuse Thoss\\GapSort\\SortModel;\n\npublic function sort(SortRequest $request)\n{\n    return $this-\u003edispatchSync(new SortModel(MyModel::class));\n}\n```\n\n\n## Example Requests with a 100 gap\n\nItem1 is sorted between 2 and 3\n```\nCurrent List:\n- Item1 (order 100)\n- Item2 (order 200)\n- Item3 (order 300)\n\nPOST /api/myresource/sort\n{\n    \"main\": 1,\n    \"previous\": 2, \n    \"next\": 3,\n}\n\nAfter Sort:\n- Item2 (order 200)\n- Item1 (order 250)\n- Item3 (order 300)\n```\n\n\nItem1 is sorted to the last\n```\nCurrent List:\n- Item1 (order 100)\n- Item2 (order 200)\n- Item3 (order 300)\n\nPOST /api/myresource/sort\n{\n    \"main\": 1,\n    \"previous\": 3, \n}\n\nAfter Sort:\n- Item2 (order 200)\n- Item3 (order 300)\n- Item1 (order 350)\n```\n\nItem3 is sorted to the first\n```\nCurrent List:\n- Item1 (order 100)\n- Item2 (order 200)\n- Item3 (order 300)\n\nPOST /api/myresource/sort\n{\n    \"main\": 3,\n    \"next\": 1, \n}\n\nAfter Sort:\n- Item3 (order 50)\n- Item1 (order 100)\n- Item2 (order 200)\n```\n\n## Testing\n\n\n```bash\ncomposer test\n```\n\n## Alternatives\n- [https://github.com/ninoman/laravel-sortable](https://github.com/ninoman/laravel-sortable)\n- [https://github.com/spatie/eloquent-sortable](https://github.com/spatie/eloquent-sortable)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthoss%2Flaravel-gap-sort","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthoss%2Flaravel-gap-sort","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthoss%2Flaravel-gap-sort/lists"}