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

Dewilas's avatar

how to group table bay date and time

Hello, i have foreach with notification messages:

<div class="row">
                    <div class="col-lg-12">
                        @foreach ($message as $items)
                        <table class="table notifications">
                            <thead>
                                <tr>
                                    <th colspan="3">{{ getDayName($items->created_at) }}</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td class="date">{{ date("g:i a", strtotime($items->created_at)) }}</td>
                                    <td class="icon"><span class="info-{{ $items->level }}"></span></td>
                                    <td><strong>{{ ucwords($items->name) }}</strong>: {{ $items->message }}</td>
                                </tr>
                            </tbody>
                        </table>
                        @endforeach
                    </div>
                </div>
                <div class="row">
                    <div class="col-lg-12">{{ $message->links(); }}</div>
                </div>
message = Auth::user()->Notifications()->orderBy('created_at', 'desc')->paginate(2);

i got result like this: march 11, 08:30 text macrh 12, 00:00 text march 12, 10:00 text but i need group date and time, for example march 11, 08:30 text macrh 12, 00:00 text 10:00 text how can i do that please help

with the same time in date in one table

0 likes
2 replies
Dewilas's avatar

i just doing like this:

$message = Auth::user()->Notifications()->orderBy('created_at', 'desc')->paginate(2);
    $message->groupBy(function($date) {
                return $date->created_at->format('M d'); // grouping by day
            });

and this is my blade

                <div class="row">
                    <div class="col-lg-12">
                        @foreach ($message as $date => $items)
                        <table class="table notifications">
                            <thead>
                                <tr>
                                    <th colspan="3">{{ getDayName($date) }}</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach ($items as $item)
                                <tr>
                                    <td class="date">{{ date("g:i a", strtotime($item->created_at)) }}</td>
                                    <td class="icon"><span class="info-{{ $item->level }}"></span></td>
                                    <td><strong>{{ ucwords($item->name) }}</strong>: {{ $item->message }}</td>
                                </tr>
                                @endforeach
                            </tbody>
                        </table>
                        @endforeach
                    </div>
                </div>

but how to paginate after grouping? i got error than im adding to the blade {{ $message->links()}}

Please or to participate in this conversation.