# fluent-cart/1.6.4/app/Models/Query/Sort.php

FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler, version 1.6.4. 35 lines.

- Page: https://pluginprobe.com/plugins/fluent-cart/1.6.4/code/app/Models/Query/Sort.php
- Raw: https://pluginprobe.com/plugins/fluent-cart/1.6.4/raw/app/Models/Query/Sort.php
- Modified: 2026-04-07T13:41:30+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/fluent-cart/1.6.4/code/app/Models/Query/Sort.php#L10-L20`.

```php
<?php

namespace FluentCart\App\Models\Query;

use FluentCart\Framework\Database\Orm\Builder;
use FluentCart\Framework\Support\Arr;

class Sort
{
    static function make(): Sort
    {
        return new static();
    }


    public function apply(Builder $query, array $sortCriteria)
    {
        if (empty($sortCriteria)) {
            return;
        }

        foreach ($sortCriteria as $key => $criteria) {
            $key = Arr::get($criteria, 'key');
            if (empty($key)) {
                continue;
            }
            // Validate column name to prevent SQL injection — only allow alphanumeric, underscores, and dots (for table.column)
            if (!preg_match('/^[a-zA-Z_][a-zA-Z0-9_.]*$/', $key)) {
                continue;
            }
            $order = Arr::get($criteria, 'order') === 'descending' ? 'desc' : 'asc';
            $query->orderBy($key, $order);
        }
    }
}
```
