Laravel count 3 tickets per time and display ticket number, date and results
Tags: help, laravel
Published: 2023-02-05 21:22:33

I have already opened a discussion where I received help for some problems I had, now I would like to improve the code but I need help. I would like to display the ticket number, date and result in the same table which currently only displays the results of counting tickets every hour. Eventually I should have a complete table of data to view. I have to do the count from 07:00 to 15:00 every day and count the tickets every hour He currently works with a set date but I would like to automate the monthly count and thus have monthly reports for each year. Thanks to all who help me and give their contribution. the problem is that now i see the count but i can't insert the ticket_id and the created_at in the table too and i need to see these two fields too together with the count
```
for ($month = 1; $month <= 12; $month++) {
            $startOfMonth = Carbon::now()->startOfMonth();
            $endOfMonth = Carbon::now()->endOfMonth();

            $uptimeData = Ticket::whereBetween('created_at', [$startOfMonth->format('Y-m-d 07:00:00'), $endOfMonth->format('Y-m-d 15:00:00')])
                        ->orderBy('created_at', 'asc')
                        ->select('ticket_Id', 'created_at')
                        ->get();
            $intervals = \Carbon\CarbonInterval::hours(1)->toPeriod($startOfMonth, $endOfMonth);
            $uptimeDataTimeline = $uptimeData->groupBy(function ($item, $key) use ($intervals) {
                $date = Carbon::parse($item->created_at);
                foreach ($intervals as $key => $interval) {
                    if ($date->hour == Carbon::parse($interval)->addHours(1)->hour) {
                    $actualHour1 = Carbon::parse($interval)->hour;
                    if (strlen($actualHour1) == 1) $actualHour1 = "0$actualHour1";
                    return $date->format("Y-m-d $actualHour1:00:00");
                    }
                    else if ($date->hour == Carbon::parse($interval)->addHours(1)->hour) {
                    $actualHour2 = Carbon::parse($interval)->subHours(1)->hour;
                    if (strlen($actualHour2) == 1) $actualHour2 = "0$actualHour2";
                    return $date->format("Y-m-d $actualHour2:00:00");
                    }

                }
            return $date->format('Y-m-d H:00:00');
            });

            $uptimeDataTimeline = $uptimeDataTimeline->map(function($checksInPeriod, $key){
                $down = 0;
                $up = 0;
                $total = 0;
                $uptime = 0;
                $fill = '#1fc777';

                foreach($checksInPeriod as $key => $value){
                    $total++;
                    if ($total <= 4) {
                        $up++;
                    } else {
                        $down++;
                    }
                }

                $uptime = floatval(number_format(round($up / $total, 5) * 100, 2, '.',','));

                if ($uptime < 100) $fill = '#9deab8';
                if ($uptime < 99) $fill = '#fbaa49';
                if ($uptime < 98) $fill = '#e0465e';

                return [
                    'total_ticket_Id' => $total,
                    'down_ticket_Id' => $down,
                    'up_ticket_Id' => $up,
                    'uptime' => $uptime,
                    'fill' => $fill,
                ];
            });
        }

<tbody>                                         
  @foreach((array)$dataset as $ticket)
   <tr>
    <td>                                                       
      {{$ticket['created_at']}}
    </td>
    <td>
      {{ $ticket['ticket_Id'] }}
    </td>
   </tr>
  @endforeach
</tbody>
```