Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

cloude's avatar

SortDesc and SortBy Collection for custom data

I have one eloquent query and two custom array. $priority_call -> is a list ('pending','await', etc.) created by $collection->filter based on conditional query. $queue_list -> is a list ('high', 'medium', 'low') is a static array. $data_cal = is results of a query column.

How can I sort like this? priority_call -> sort by DESC queue_list -> sort by ASC (here solved with array_reverse) data_cal -> sort by ASC(here is my problem)

    $collection = $collection->sortByDesc(function($leads) use($request) {

        $priority_call = $this->priorityCall($leads->status_group);
        $queue_list = array_search($leads->status_group, array_reverse(explode(',',$leads->online_operators->queue_list))); 
        $data_cal = $leads->data_cal;

        return [
            $priority_call, 
            $queue_list
            $data_cal, 
        ];

    })->values();
0 likes
0 replies

Please or to participate in this conversation.