Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sorting json column don't work #196

Open
divdax opened this issue Mar 3, 2022 · 1 comment
Open

Sorting json column don't work #196

divdax opened this issue Mar 3, 2022 · 1 comment

Comments

@divdax
Copy link

divdax commented Mar 3, 2022

Hi,

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

->sortable('name->en')

The database query doesn't contain any order by.

@JoseVte
Copy link

JoseVte commented Jul 28, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants