Kyslik / column-sortable

Package for handling column sorting in Laravel 5/6/7/8
MIT License
644 stars 105 forks source link

Sorting json column don't work #196

Open divdax opened 2 years ago

divdax commented 2 years ago

Hi,

i tried to sort by name column (datatype: json) with:

->sortable('name->en')

The database query doesn't contain any order by.

JoseVte commented 2 years ago

Hi, I had the same issue, but debugging how the query is built, I discorver that you can put alias to the order, and that alias are translate to correct JSON order from eloquent.

This is my code:

protected array $sortableAs = [
        'name->en',
        'name->es',
    ];
@sortablelink('name->en')

With this, eloquent generates this:

select * from exercises order by json_unquote(json_extract(name, '$."en"')) asc limit 15 offset 0