public function index() { $overdueBills = \App\Bill::before(date('Y-m-d'), false); $nextUnpaidBills = \App\Bill::next(30, false); $nextPaidBills = \App\Bill::next(30, true); $lastPaidBills = \App\Bill::before(date('Y-m-d'), true); // refactor into REPORTS $report = array(); // get months for ($month = 1; $month <= 12; $month++) { $startDate = mktime(0, 0, 0, $month, 1, date('Y')); $stopDate = mktime(0, 0, 0, $month, date('t', $startDate), date('Y')); $bills = \App\Bill::between(date('Y-m-d', $startDate), date('Y-m-d', $stopDate), true); $report['months'][] = date('F Y', $startDate); $report['amounts'][] = $bills->sum('amount'); } return view('home.index')->with('overdueBills', $overdueBills)->with('nextUnpaidBills', $nextUnpaidBills)->with('nextPaidBills', $nextPaidBills)->with('lastPaidBills', $lastPaidBills)->with('report', json_encode($report)); }