A
A
Alexander2019-02-04 16:48:10
MySQL
Alexander, 2019-02-04 16:48:10

How to sort database records by json object in Laravel?

Friends, good afternoon.
Please tell me how to solve the following situation (Laravel framework):
There is a table rows:
id name
And there is a table rows_user_sort:
user_id sort
in the sort field is a json object with row.id and sort - the serial number for sorting:
[{"id" : 244, "sort": 0}, {"id": 4, "sort": 1}, {"id": 20, "sort": 2}, {"id": 21, "sort": 3 }, {"id": 22, "sort": 4}, {"id": 15, "sort": 5}, {"id": 24, "sort": 6}]
How can rows be sorted by similar json object?
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg, 2019-02-04
@402d

is that what prevented you from doing rows_user_sort {user_id, row_id,sort_weight} ?
And now sort the array of results in PHP code
or collect the sql query with order by find_in_set()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question