I'm working on learning a bit about laravel, and I'm a little unsure of what the proper route is for the following:
I want to have a user dashboard that shows the user's total messages, divided up by the read / unread messages, as well as a task list showing upcoming tasks as well as overdue tasks.
Right now the way I'm looking at doing this is setting these values in the controller:
// 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');
}
This seems really a bit pointless and repetitive. Is there a way to return the total messages
result to the view and then split them up by read / unread there, or is it smarter to create functions in the model that will return these number directly? Or maybe I'm totally missing the right way?
Thanks