I want to create an API ,I have this controller which return data grouped by date:
public function dated_matchs()
{
$mdate = Match::all()->groupBy('m_date');
return $mdate;
}
the result is like this :
{
"2021-02-26": [
{
"id": 2,
"week_season": 1,
"week_number": 1,
"m_hour": "21:31:28",
"m_date": "2021-02-26",
}
],
"2021-02-27": [
{
"id": 7,
"week_season": 1,
"week_number": 1,
"m_hour": "21:37:04",
"m_date": "2021-02-27",
}
]
}
I want to be something like this:
{
"date":"2021-02-26"
"matches": [
{
"id": 2,
"week_season": 1,
"week_number": 1,
"m_hour": "21:31:28",
"m_date": "2021-02-26",
},
],
"date":"2021-02-27"
"matches": [
{
"id": 7,
"week_season": 1,
"week_number": 1,
"m_hour": "21:37:04",
"m_date": "2021-02-27",
}
]
}
How can I add date name to the data returned from API
question from:https://stackoverflow.com/questions/65943986/laravel-show-the-field-name-which-grouped-by