{"id":19199976,"url":"https://github.com/fusic/laravel-sortable","last_synced_at":"2026-02-25T06:36:07.209Z","repository":{"id":45454923,"uuid":"371992161","full_name":"fusic/laravel-sortable","owner":"fusic","description":null,"archived":false,"fork":false,"pushed_at":"2023-11-02T07:18:52.000Z","size":23,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-10-28T14:48:05.295Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fusic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2021-05-29T14:22:14.000Z","updated_at":"2021-12-13T03:33:49.000Z","dependencies_parsed_at":"2024-11-09T12:30:23.488Z","dependency_job_id":"3442f70e-8740-4527-af9a-ad7aaa6f1597","html_url":"https://github.com/fusic/laravel-sortable","commit_stats":{"total_commits":25,"total_committers":3,"mean_commits":8.333333333333334,"dds":0.6,"last_synced_commit":"2395b5e706b915426313f64639933174389a5c74"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/fusic/laravel-sortable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fusic%2Flaravel-sortable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fusic%2Flaravel-sortable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fusic%2Flaravel-sortable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fusic%2Flaravel-sortable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fusic","download_url":"https://codeload.github.com/fusic/laravel-sortable/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fusic%2Flaravel-sortable/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29812618,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-25T05:36:42.804Z","status":"ssl_error","status_checked_at":"2026-02-25T05:36:31.934Z","response_time":61,"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":[],"created_at":"2024-11-09T12:29:48.021Z","updated_at":"2026-02-25T06:36:07.192Z","avatar_url":"https://github.com/fusic.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel-Sortable\nEasily generate a link to switch the sort state for `\u003ctable\u003e` and so on.\n\n## Install\nAdd this repository to `composer.json` then `$ composer install`.\n```\n\"repositories\": [\n        {\n            \"type\": \"vcs\",\n            \"url\": \"git@github.com:fusic/laravel-sortable.git\"\n        }\n    ]\n```\n\nRegister the Service Provider to `config/app.php`.\n```\n'providers' =\u003e [\n    ...\n    /*\n    * Package Service Providers...\n    */\n    Sortable\\Providers\\SortableServiceProvider::class,\n    ...\n]\n```\n\n## Usage\n### Create Sortable class\nExecute artisan `make:sortable` command.\n\n```\n$ php artisan make:sortable EmployeeSortable\n```\n\n### Settings\nWrite sort keys in the created `Sortable` class.\n\n```\n\u003c?php\n\nnamespace App\\Sort;\n\nuse Sortable\\Sortable;\n\nclass EmployeeSortable extends Sortable\n{\n    public function __construct()\n    {\n        $this-\u003eparams = [  // write here!\n            'employee_number',\n            'name' =\u003e 'Employees.fullname',  // URL parameter =\u003e column name\n            'birthday' =\u003e function ($builder, $query, $sortKey, $sortDirection) {\n                // write custom 'order by' condition\n                return $builder-\u003eorderBy('foo', 'desc');\n            },\n        ];\n    }\n}\n```\n\n### Insert a Sortable object to the query\n\n```\n$employees = Employees::query()\n    -\u003ewhere('foo', 'baz')\n    /** what you want... **/\n    -\u003esort(new EmployeeSortable())\n    /** ... **/\n    ;\n```\n\nThis will add the sort condition to the query. `Sortable` can be used in both Eloquent and Query Builder.\n\n### Use @sort directive in the blade\n#### Generate a simple link\n```\n@sort(['title' =\u003e 'Name', 'key' =\u003e 'name', 'url' =\u003e '#'])\n```\n\nThis `@sort` directive will generate a link to switch the sort state like this:\n\n```\n\u003ca href=\"https://www.example.com/index?sort=name\u0026direction=asc\" class=\"sort-key\"\u003eName\u003c/a\u003e\n```\n\nThe state switches in the order of ascending, descending, and unsorting, the generated links follow the order.\n\nUsage example:\n\n```\n\u003ctable\u003e\n    \u003cthead\u003e\n        \u003ctr\u003e\n            \u003cth\u003e@sort(['title' =\u003e 'Number', 'key' =\u003e 'employee_number', 'url' =\u003e '#'])\u003c/th\u003e\n            \u003cth\u003e@sort(['title' =\u003e 'Name', 'key' =\u003e 'name', 'url' =\u003e '#'])\u003c/th\u003e\n            \u003cth\u003e@sort(['title' =\u003e 'Birthday', 'key' =\u003e 'birthday', 'url' =\u003e '#'])\u003c/th\u003e\n        \u003c/tr\u003e\n    \u003c/thead\u003e\n    \u003ctbody\u003e\n        @foreach($employees as $employee)\n        \u003ctr\u003e\n            \u003ctd\u003e{{ $employee-\u003eemployee_number }}\u003c/td\u003e\n            \u003ctd\u003e{{ $employee-\u003efullname }}\u003c/td\u003e\n            \u003ctd\u003e{{ $employee-\u003ebirthday-\u003eformat('Y/m/d') }}\u003c/td\u003e\n        \u003c/tr\u003e\n        @endforeach\n    \u003c/tbody\u003e\n\u003c/table\u003e\n```\n\n#### Generate a link with custom DOM template\nPassing the DOM templates corresponding to each sort state to `@sort` directive, `Sortable` will generate links according to it.\n\n```\n@sort([\n    'key' =\u003e 'name',\n    'default' =\u003e '\u003cspan class=\"text-black\"\u003eName\u003c/span\u003e',\n    'asc' =\u003e '\u003cspan class=\"text-red asc\"\u003eName↑\u003c/span\u003e',\n    'desc' =\u003e '\u003cspan class=\"text-blue desc\"\u003eName↓\u003c/span\u003e',\n])\n```\n\nThis will generate a custom link:\n\n```\n\u003ca href=\"https://www.example.com/index?sort=name\u0026direction=asc\" class=\"sort-key\"\u003e\u003cspan class=\"text-red asc\"\u003eName↑\u003c/span\u003e\u003c/a\u003e\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffusic%2Flaravel-sortable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffusic%2Flaravel-sortable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffusic%2Flaravel-sortable/lists"}