diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..2e0164d --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,35 @@ +# CLAUDE.md — column-sortable + +## Overview + +Ubiquilife fork of Kyslik's column-sortable. Adds clickable column header sorting to Eloquent queries. Used by Appbase's QoModel to provide automatic table column sorting on every feature's index view. + +## Namespace + +`Kyslik\ColumnSortable` + +## Key Classes + +- **`Sortable`** — Trait for Eloquent models. Adds `scopeSortable()` which reads `sort` and `direction` from the request query string and applies `ORDER BY`. Supports sorting through `BelongsTo` and `HasOne` relationships. +- **`SortableLink`** — Blade helper to render sortable column headers with directional arrows. Usage: `@sortablelink('name', 'Display Name')`. +- **`ColumnSortableServiceProvider`** — Auto-discovered. Publishes config, registers Blade directive. +- **`Exceptions\ColumnSortableException`** — Thrown when an unsortable column is requested. + +## Configuration + +Sortable columns are defined per model via `$sortable` array property. Global config in `config/columnsortable.php`. + +## Testing + +```bash +cd column-sortable && vendor/bin/phpunit +``` + +## Mandatory Rules + +- This is a PRIVATE Ubiquilife package. Changes affect ALL apps. +- NEVER change the `Sortable` trait API or query string parameter names (`sort`, `direction`) — every index view depends on these. +- NEVER change `SortableLink` output HTML without checking Appbase table templates. +- Use British spelling in all text and comments. +- Test before committing. +- One logical change per commit. diff --git a/composer.json b/composer.json index 0d49bdd..b57d46c 100755 --- a/composer.json +++ b/composer.json @@ -19,8 +19,8 @@ ], "require": { "php": ">=7.2", - "illuminate/support": "5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0", - "illuminate/database": "5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0" + "illuminate/support": "5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0", + "illuminate/database": "5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0" }, "require-dev": { "phpunit/phpunit": "^8.5|^9.5.10|^10.5|^11.5.3", diff --git a/src/ColumnSortable/SortableLink.php b/src/ColumnSortable/SortableLink.php index 8499acb..fec3d98 100644 --- a/src/ColumnSortable/SortableLink.php +++ b/src/ColumnSortable/SortableLink.php @@ -252,7 +252,14 @@ private static function buildQueryString($queryParameters, $sortParameter, $dire }; $persistParameters = array_filter(request()->except('sort', 'direction', 'page'), $checkStrlenOrArray); - $queryString = http_build_query(array_merge($queryParameters, $persistParameters, [ + if (config('columnsortable.swap_querystring_params') == false) { + $parameters[0] = $queryParameters; + $parameters[1] = $persistParameters; + } else { + $parameters[0] = $persistParameters; + $parameters[1] = $queryParameters; + } + $queryString = http_build_query(array_merge($parameters[0], $parameters[1], [ 'sort' => $sortParameter, 'direction' => $direction, ])); diff --git a/src/config/columnsortable.php b/src/config/columnsortable.php index 51b54b9..f4cb7aa 100755 --- a/src/config/columnsortable.php +++ b/src/config/columnsortable.php @@ -118,4 +118,14 @@ for more information see https://github.com/Kyslik/column-sortable/issues/59 */ 'join_type' => 'leftJoin', + + /* + SortableLink.php:buildQueryString() + + when building sortable links, pass the parameters like this if false (default): + array_merge($persistParameters, $queryParameters, + otherwise swap the order + array_merge($queryParameters, $persistParameters, + */ + 'swap_querystring_params' => false, ];