Add ReportsController
ADD
app/Http/Controllers/ReportsController.php
+<?php
+
+namespace App\Http\Controllers;
+
+use Illuminate\Http\Request;
+
+use Auth;
+use DB;
+
+class ReportsController extends Controller {
+ public function get() {
+ $user = Auth::user();
+
+ $currentYear = date('Y');
+
+ $monthlyEarnings = [];
+
+ for ($i = 1; $i <= 12; $i ++) {
+ $monthlyEarnings[] = $user->earnings()->whereRaw('MONTH(date) = ?', [$i])->sum('amount');
+ }
+
+ $monthlySpendings = [];
+
+ for ($i = 1; $i <= 12; $i ++) {
+ $monthlySpendings[] = $user->spendings()->whereRaw('MONTH(date) = ?', [$i])->sum('amount');
+ }
+
+ return view('reports', compact('currentYear', 'monthlyEarnings', 'monthlySpendings'));
+ }
+}

MODIFY
resources/views/layout.blade.php
resources/views/layout.blade.php
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Muli:400,400i" />
<link rel="stylesheet" href="/css/app.css" />
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.bundle.min.js"></script>
</head>
<body>
<div id="app">
<li>
<a href="/tags"><i class="fa fa-tag"></i> @lang('general.tags')</a>
</li>
+ <li>
+ <a href="/reports"><i class="fa fa-pie-chart"></i> Reports</a>
+ </li>
</ul>
<ul>
<li>
@yield('body')
</div>
<script src="/js/app.js"></script>
+ @yield('scripts')
</body>
</html>

ADD
resources/views/reports.blade.php
+@extends('layout')
+
+@section('body')
+ <div class="banner">
+ <h1>Reports for {{ $currentYear }}</h1>
+ </div>
+ <div class="wrapper spacing-top-large spacing-bottom-large">
+ <div class="box">
+ <div class="section">
+ <canvas id="earningsSpendingsChart"></canvas>
+ </div>
+ </div>
+ </div>
+@endsection
+
+@section('scripts')
+ <script>
+ var context = document.getElementById('earningsSpendingsChart').getContext('2d');
+
+ var chart = new Chart(context, {
+ type: 'line',
+
+ data: {
+ labels: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
+
+ datasets: [
+ {
+ label: 'Earnings',
+ data: {!! json_encode($monthlyEarnings) !!},
+ borderColor: 'rgba(151, 206, 86, 1)',
+ backgroundColor: 'rgba(151, 206, 86, .1)'
+ },
+
+ {
+ label: 'Spendings',
+ data: {!! json_encode($monthlySpendings) !!},
+ borderColor: 'rgba(255, 95, 94, 1)',
+ backgroundColor: 'rgba(255, 95, 94, .1)'
+ }
+ ]
+ },
+
+ options: {
+ animation: {
+ duration: 0
+ },
+
+ elements: {
+ line: {
+ tension: .2
+ }
+ }
+ }
+ });
+ </script>
+@endsection

MODIFY
routes/web.php
routes/web.php
@@ -33,6 +33,8 @@ Route::group(['middleware' => ['auth']], function () {
Route::patch('/tags/{tag}', 'TagsController@update')->middleware('can:update,tag');
Route::delete('/tags/{tag}', 'TagsController@destroy')->middleware('can:delete,tag');
+ Route::get('/reports', 'ReportsController@get')->name('reports');
+
Route::get('/settings', 'SettingsController@index')->name('settings');
Route::post('/settings', 'SettingsController@store');
});

Add ReportsController