- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 78
Open
Description
I'm trying to sort collection in many ways but not result, each time $complaintsSearch returned unsorted data.
Few examples:
$complaints = (new Complaint);
$sortBy = [['complaints_date','desc'],['city','desc']];
            $complaintsSearch = Search::add($complaints, 'company_name')
                ->search('"' . $searchText . '"');
                            $complaintsSearch = $complaintsSearch->toArray();
            usort($complaintsSearch, function($a, $b) {
                return -strcmp($a['complaint_date'], $b['complaint_date']);
            });
            
            $complaintsSearch = collect($complaintsSearch);
            $complaintsSearch = $complaintsSearch->sortByDesc(function ($item) {
                return (string) $item['complaint_date'];
            });
            $complaintsSearch = $complaintsSearch->sortBy(function($complaintsSearch) use ($sortBy) {
                foreach ($sortBy as $sort) {
                    $column = $sort[0];
                    $direction = $sort[1];
                    if ($direction == 'asc') {
                        return $complaintsSearch->$column;
                    } else {
                        return $complaintsSearch->$column;
                    }
                }
And I also trygin sorting data before pass it.
$complaints->orderBy($sortBy);
Each time it returned unsorted collection I don't know why.
Sorting working correctly without use Search
Sorry for misspelled
Thank you.
Metadata
Metadata
Assignees
Labels
No labels