【发布时间】:2015-03-04 17:26:16
【问题描述】:
我正在努力学习一些有关 laravel 的知识,但我有点不确定以下的正确路线是什么:
我想要一个用户仪表板,显示用户的总消息,除以已读/未读消息,以及显示即将执行的任务和过期任务的任务列表。
现在我正在考虑这样做的方式是在控制器中设置这些值:
// the user index controller function
public function getIndex()
{
$read = Message::where('user_id', '=', Auth::user()->id)
->where('read', '=', 1);
$unread = Message::where('user_id', '=', Auth::user()->id)
->where('read', '=', 0);
// etc
return View::make('user.index');
}
这似乎真的有点毫无意义和重复。有没有办法将messages 的总结果返回到视图,然后在那里通过 read / unread 将它们拆分,或者在模型中创建将直接返回这些数字的函数是否更聪明?或者也许我完全错过了正确的方式?
谢谢
【问题讨论】: