get(); $incidents = $this->getIncidents(); return View::make('dashboard.index') ->withComponents($components) ->withIncidents($incidents); } /** * Shows the notifications view. * * @return \Illuminate\View\View */ public function showNotifications() { return View::make('dashboard.notifications.index') ->withPageTitle(trans('dashboard.notifications.notifications').' '.trans('dashboard.dashboard')); } /** * Fetches all of the incidents over the last 30 days. * * @return \Illuminate\Support\Collection */ protected function getIncidents() { $incidents = Incident::select(DB::raw('COUNT(id) AS counter'))->groupBy(DB::raw('DATE_FORMAT(created_at, "%d%m%y")'))->get(); $range = (30 - $incidents->count()) - 1; $fake = new stdClass(); $fake->counter = 0; foreach (range(1, $range) as $key) { $incidents->prepend($fake); } return $incidents; } }