Kyslik/column-sortable

Sorting json column don't work

Opened this issue · 1 comments

Hi,

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

->sortable('name->en')

The database query doesn't contain any order by.

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:

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

With this, eloquent generates this:

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