Help with Query for table
Hello. Trying to make a table(html) with some data. I have this table with fake data so you could see how it is going to look like: https://i.imgur.com/ocpQp6q.png
For this I need to use two tables(db)
- Booking, where the customer and his arrival time and date is.
- Delivery, where the column delivery_location is.
So an example. Let's take the row 235 at 18 a clock. Where you can see the number 2. This means : It is two cars which has an arrivalDate today and arrival time is between 18 and 19 and their "delivery_location in delivery table" is 235.
Table thead th: "Rekke" is delivery_location, "ant" is the amount of cars on that "rekke" and "passert" is amount of cars which has not yet been prepared. This means when the car is ready for delivery we click prepare and it will be removed from the table. If this is not done and the time has passed for that car it should be listed in there.
From the third "thead th" you can see it starts with 18. That means time right now in format ( H ) and every th after that just increment with 1 hour until 12 hors since first.
This is what I do now:
public function index()
{
$time_now = Carbon::now();
$setStartHour = $time_now->minute(0)->second(0);
$labels = [];
$rows = [
'rows' => [
]
];
try{
for($i = 0; $i < 12; $i++) {
$startTime = $setStartHour->format("H:i:s");
$labelString = $setStartHour->format("H");
$arrival = Booking::with('delivery')
->where('status', 3)
// ->whereBetween('arrivalDate', [today(), now()->modify('+1 day')])
->whereBetween('arrivalTime', [$startTime, Carbon::parse($startTime)->addMinutes(60)])
->count();
$labels[] = $labelString;
$rows['rows'][] = $arrival;
$setStartHour->modify('60 minutes');
}
} catch (\Exception $e) {
return ['status' => false, 'message' => $e->getMessage()];
}
$data = [
'data' => $rows,
'labels' => $labels
];
return view('admin/pages/pickup.index', compact('data'));
So now in the $data['data] it displays each hour from now and 12 hours ahead with the correct data. If i loop this in blade
@foreach($data['data']['rows'] as $rows)
<th> {{ $rows}} </th>
@endforeach
I get the correct numbers under the correct time in thead, BUT they are only on one line..becuase they dont know which delivery_location they belong to. suggestions?
Please or to participate in this conversation.