Not sure at all, but could it a casting problem on the date ?
Dec 17, 2022
7
Level 8
How to sort a collection by multiple attributes : user_name then by date and then by quarter
Hello,
I want to export a collection to excel but first I want to sort by :
user_name then by date then by quarter as you can see bellow
Illuminate\Support\Collection {#1603 ▼
#items: array:5 [▼
0 => {#1443 ▼
+"user_id": 172
+"user_name": "David Hervy"
+"date": "2022-09-30"
+"quarter": "Q4"
}
1 => {#1473 ▼
+"user_id": 172
+"user_name": "Sandra Tuner"
+"date": "2022-09-30"
+"quarter": "Q3"
}
2 => {#1459 ▶}
3 => {#1476 ▶}
4 => {#1626 ▶}
]
#escapeWhenCastingToString: false
}
It works if I sort only by user_name and quarter
return Excel::download(new InsightsPlanningExport(
collect($queryEmptyDates)->merge($this->plannings->get())
->sortBy([
['user_name','asc'],
['quarter','asc'],
])
), 'file_name.xlsx');
BUT if I add date :
return Excel::download(new InsightsPlanningExport(
collect($queryEmptyDates)->merge($this->plannings->get())
->sortBy([
['user_name','asc'],
['date','asc'],
['quarter','asc'],
])
), 'file_name.xlsx');
It returns Error : date() expects parameter 1 to be string, object given
Please or to participate in this conversation.