Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ramur's avatar
Level 1

Laravel livewire How to show data in table according to date

hello im new for laravel livewire im trying to foreach data to table by date wise.

EXAMPLE I taken attendance on 1/1/24 table header show DATE-1/1/24 AND ROW Show that date record if we not taken attendance on 2/1/24 than table Hader show DATE-2/1/24 AND ROW Show - means attendance not taken

example

im trying to get this
   |  name    |    STD_ID   |    DATE-1/1/24   |   DATE-2/1/24 |  DATE-3/1/24 | DATE-4/1/24 |
   |  john    |    STD_01   |         P        |       -       |       P      |      A      |
   |  sean    |    STD_02   |         P        |       -       |       P      |      P      |
**CONTROLLER**
``
  $this->Data= Attendance::get();
  //This Code Use For Multiple Coleman Marg In single row by student_id 
 $grouped =  $this->Data->groupBy('student_id');
 $this->Attendance_Data = $grouped->all();
``

**BLADE VIEW**

`<table>
   <thead> 
       <tr> 
         <th>NAME</th>
         <th>STD_ID</th>
         <th>DATE-1/1/24</th>
         <th>DATE-2/1/24</th>
         <th>DATE-3/1/24</th>
         <th>DATE-......</th>
         <th>DATE-31/1/24</th>
  </thead>
<tbody>
  @foreach ($this->Attendance_Data as $key=>$Attendance_Datas)                                          
<tr> 
   <td>{{$Attendance_Datas[0]->name}}</td>
   <td>{{$Attendance_Datas[0]->std_id}}</td>
 @foreach ($Attendance_Datas as $key=>$Attendance)
   <td>{{$Attendance->attendance}} </td>
 @endforeach  
</tr>
   @endforeach
   @endif 
    </tbody> 
</table> `

DATABASCE

id  |     name      |student_id   |  date_of_attendance |   attendance |
1   |    john       |    STD_01   |     2024-01-01      |       P      |
2   |    john       |    STD_01   |     2024-01-03      |       P      |
2   |    john       |    STD_01   |     2024-01-04      |       A      |
3   |    sean       |    STD_02   |     2024-01-01      |       P      |
4   |    sean       |    STD_02   |     2024-01-03      |       P      |
2   |    sean       |    STD_02   |     2024-01-04      |       P      |

i tryid in if and else but not get proper result

0 likes
0 replies

Please or to participate in this conversation.