Move logic for reports to separate functions in their controller
MODIFY
app/Http/Controllers/ReportController.php
app/Http/Controllers/ReportController.php
@@ -10,8 +10,7 @@ class ReportController extends Controller {
return view('reports.index');
}
- public function show($slug) {
- if ($slug == 'weekly-report-2018') {
+ private function weeklyReport2018() {
$weeks = [];
$balance = 0;
@@ -35,7 +34,7 @@ class ReportController extends Controller {
]);
}
- if ($slug == 'most-expensive-tags') {
+ private function mostExpensiveTags() {
$mostExpensiveTags = DB::select('
SELECT
tags.name AS name,
@@ -60,6 +59,16 @@ class ReportController extends Controller {
return view('reports.most_expensive_tags', compact('mostExpensiveTags', 'totalSpent'));
}
+ public function show($slug) {
+ switch ($slug) {
+ case 'weekly-report-2018':
+ return $this->weeklyReport2018();
+
+ case 'most-expensive-tags':
+ return $this->mostExpensiveTags();
+
+ default:
return '404';
}
}
+}

Move logic for reports to separate functions in their controller