Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 8 additions & 1 deletion src/ColumnSortable/SortableLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]));
Expand Down
10 changes: 10 additions & 0 deletions src/config/columnsortable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];