Sort by json column with one-to-one relationship in Laravel

15 Views Asked by At

How to sort by a json column with the relationship in laravel; My code:

    $query = DispatchStatus::query();
    $query->has("order");
    $column = "name";
    $sortBy  = "desc";
    $query->with("order", function ($subQuery) use ($column, $sortBy) {
        info($column . "__" . $sortBy);
        $subQuery->orderBy('recipient->' . $column, $sortBy);
    });
    $results = $query->paginate();

I got the unsorted results! How can I sort by the recipient name in the JSON column?

0

There are 0 best solutions below