我需要用laravel按日和时间对表进行分组。我有数组对象,我选择一些信息(控制器):
public function getNotification()
{
$message = Auth::user()->Notifications()->orderBy('created_at', 'desc')->get();
$this->layout->content = View::make('auth/main')->with(array(
'data' => View::make('auth/dashboard')->with([
'message' => $message
]),
'fluid' => true
));
}
这是我的DB:
id/message/name/created_at
1 some text announcement 2015-03-11 10:24:05
2 some text announcement 2015-03-11 08:24:05
2 some text announcement 2015-03-10 14:24:05
4 some text announcement 2015-03-08 12:24:05
这是blade tmpl:
<table class="table notifications">
<thead>
<tr>
<th colspan="3">YESTERDAY</th>
</tr>
</thead>
<tbody>
<tr>
<td class="date">8:59 am</td>
<td class="icon"><span class="info-red"></span>
</td>
<td><strong>Announcement</strong>: As business grows, we all need to adapt. You've been growing, and receiving bigger amounts of orders. We've noticed the need for printing high volumes of the same kind of design. You've been growing, and receiving
bigger amounts of orders. We've noticed the need for printing high volumes of the same kind of design.You've been growing, and receiving bigger amounts of orders. We've noticed the need for printing high volumes of the same kind of design.You've
been growing, and receiving bigger amounts of orders. We've noticed the need for printing high volumes of the same kind of design.
</td>
</tr>
<tr>
<td class="date">8:59 am</td>
<td class="icon"><span class="info-green"></span>
</td>
<td><strong>Announcement</strong>: As business grows, we all need to adapt. You've been growing, and receiving bigger amounts of orders. We've noticed the need for printing high volumes of the same kind of design. You've been growing, and receiving
bigger amounts of orders. We've noticed the need for printing high volumes of the same kind of design.You've been growing, and receiving bigger amounts of orders. We've noticed the need for printing high volumes of the same kind of design.You've
been growing, and receiving bigger amounts of orders. We've noticed the need for printing high volumes of the same kind of design.
</td>
</tr>
</tbody>
</table>
<table class="table notifications">
<thead>
<tr>
<th colspan="3">FEBRUARY 06</th>
</tr>
</thead>
<tbody>
<tr>
<td class="date">8:59 am</td>
<td class="icon"><span class="info-red"></span>
</td>
<td><strong>Announcement</strong>: As business grows, we all need to adapt. You've been growing, and receiving bigger amounts of orders. We've noticed the need for printing high volumes of the same kind of design. You've been growing, and receiving
bigger amounts of orders. We've noticed the need for printing high volumes of the same kind of design.You've been growing, and receiving bigger amounts of orders. We've noticed the need for printing high volumes of the same kind of design.You've
been growing, and receiving bigger amounts of orders. We've noticed the need for printing high volumes of the same kind of design.
</td>
</tr>
</tbody>
</table>
我需要像我的刀片一样的结果:
在一个表中来自db的1和2 ID,因为它们是今天的组, 第二个表中有3个id,第三个表中有4个id
如何按日分组表格以及它的外观可能与我的刀片tmpl一样?
答案 0 :(得分:0)
试试这个..
$message = Auth::user()->Notifications()->orderBy('created_at', 'desc')->groupBy('created_at')->get();
答案 1 :(得分:0)
问题解决了:
$message = Auth::user()->Notifications()->orderBy('created_at', 'desc')->get()
->groupBy(function($date) {
return Carbon::parse($date->created_at)->format('M d'); // grouping by day
});
如何分页?