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

fikri1510's avatar

Hiding duplication date in blade view

How do I hide the repetition date in the record in blade view, such as

Date                      | Requester     | Issues
==========================================
13/01/2019           | Lucia    | Application
13/01/2019           | Gersie   | Hardware
13/01/2019           | Pat      | Application
13/01/2019           | Jack     | Application

Date                      | Requester | Issues
==========================================
14/01/2019           | Lucia    | Application
14/01/2019           | Pat          | Other

Date                      | Requester | Issues
==========================================
15/01/2019           | Lucia    | Application
15/01/2019           | Robert    | Other
15/01/2019           | Emmy     | Hardware


become


Date                      | Requester | Issues
==========================================
13/01/2019           | Lucia    | Application
                             | Gersie   | Hardware
                             | Pat      | Application
                             | Jack     | Application

Date                      | Requester| Issues
==========================================
14/01/2019           | Lucia    | Application
                              | Pat         | Other

Date                      | Requester| Issues
==========================================
15/01/2019           | Lucia    | Application
                              | Robert    | Other
                              | Emmy     | Hardware


If I used group by date, only one row shows. Another approach is to make if else in blade with checking if the counting date > 1 then hide the date

SELECT CAST(created_at AS date), COUNT(id) as 'totalTask' from tasks GROUP BY CAST(created_at as date)

it counts total of duplication date, but I don't know how to check it the date in the blade.

<?php

                                foreach($tasks as $task){?>
                                <tr>
                                    @if($task->created_at->toDateString())
                                    <td>{{date('jS F Y', strtotime($task->created_at))}}<br/></td></tr>
                                    @else
                                        <td>{{""}}</td>
                                    @endif
                                    <td>{{\Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $task->created_at)->format('H:i:s')}}</td>
                                    <td>{{$task->requester}}</td>
                                    <td>{{$task->issue}}</td>
                                </tr>
                            <?php }?>

Thanks for helping me

0 likes
2 replies
Snapey's avatar

You can show the tabular output better by putting 3 backticks ``` on a line before and after

Can you include your blade code?

fikri1510's avatar

I solved it with simple code in the view

<tbody>
   <?php
    $initialDate = '';
                                    $nr = 1;
                                    foreach($tasks as $task){?>
                                <tr>
                                    @if($initialDate != $task->created_at->toDateString() )
                                    <td>{{date('jS, F Y', strtotime($task->created_at))}}<br/></td>
                                        <?php $initialDate = $task->created_at->toDateString();?>
                                        @else
                                        <td>{{""}}</td>
                                    @endif
                                    <td>{{$nr}}-{{$totalTask}}</td>
                                    <td>{{\Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $task->created_at)->format('H:i:s')}}</td>
                                    <td>{{$task->requester}}</td>
                                    <td>{{$task->issue}}</td>

                                </tr>

                                <?php
                                    $nr++;
                                    }?>
                            </tbody>

Please or to participate in this conversation.