Update DashboardController and EarningController to work with earnings using space_id instead of user_id
MODIFY
app/Http/Controllers/DashboardController.php
app/Http/Controllers/DashboardController.php
@@ -54,7 +54,7 @@ class DashboardController extends Controller {
'recentSpendings' => $recentSpendings,
'mostExpensiveTags' => $mostExpensiveTags,
- 'earningsCount' => $user->earnings->count(),
+ 'earningsCount' => session('space')->earnings->count(),
'spendingsCount' => session('space')->spendings->count()
]);
}

MODIFY
app/Http/Controllers/EarningController.php
app/Http/Controllers/EarningController.php
@@ -12,7 +12,7 @@ class EarningController extends Controller {
public function index() {
$user = Auth::user();
- $earnings = $user
+ $earnings = session('space')
->earnings()
->orderBy('happened_on', 'DESC')
->orderBy('created_at', 'DESC')
@@ -34,7 +34,7 @@ class EarningController extends Controller {
$earning = new Earning;
- $earning->user_id = Auth::user()->id;
+ $earning->space_id = session('space')->id;
$earning->happened_on = $request->input('date');
$earning->description = $request->input('description');
$earning->amount = (int) ($request->input('amount') * 100);

Update DashboardController and EarningController to work with earnings using space_id instead of user_id