Hi guys,
I've been tinkering around with some data that I finally managed to group as I want it to, but I can't figure out how to do this next part.
So I got this dataset:
{
10: [
{
week: "10",
Booket: 0
},
{
week: "10",
Booket: 18
},
{
week: "10",
Booket: 10
}
],
11: [
{
week: "11",
Booket: 0
},
{
week: "11",
Booket: 5
},
{
week: "11",
Booket: 5
},
{
week: "11",
Booket: 0
},
{
week: "11",
Booket: 15
}
],
12: [
{
week: "12",
Booket: 0
},
{
week: "12",
Booket: 5
},
{
week: "12",
Booket: 14
}
],
}
I want to iterate over each week, add the numbers from "Booket" and return them so I would get something like this:
{
10: [
{
week: "10",
Booket: 28
},
],
11: [
{
week: "11",
Booket: 25
},
],
12: [
{
week: "12",
Booket: 19
},
],
This is my show method:
public function show()
{
$bookings = Booking::where('SelectedDate', '>', Carbon::now()->firstOfYear())
->where('TypeID', 3)
->where('TemplateID', 18)
->where('Interval', '07:00-12:00')
->selectRaw('DATE_FORMAT(SelectedDate, "%V") as week, Booket')
->orderBy('week', 'asc')
->get();
$result = $bookings->groupBy('week');
$result = $result->groupBy(function ($item) {
return $item['Booket'];
})->all();
return view('bookings.show', compact('result'));
}
This is so I can return it to a Chart.js graph which shows the booking count for each week.
Can anyone chime in on this with a bit of expertise and fresh mind? :)