Update SpendingController and DashboardController to work with spendings using space_id
MODIFY
app/Http/Controllers/DashboardController.php
app/Http/Controllers/DashboardController.php
@@ -13,12 +13,12 @@ class DashboardController extends Controller {
$space_id = session('space')->id;
- $totalSpendings = $user
+ $totalSpendings = session('space')
->spendings()
->whereRaw('MONTH(happened_on) = ?', [date('m')])
->sum('amount');
- $recentSpendings = $user
+ $recentSpendings = session('space')
->spendings()
->orderBy('created_at', 'DESC')
->limit(3)
@@ -55,7 +55,7 @@ class DashboardController extends Controller {
'mostExpensiveTags' => $mostExpensiveTags,
'earningsCount' => $user->earnings->count(),
- 'spendingsCount' => $user->spendings->count()
+ 'spendingsCount' => session('space')->spendings->count()
]);
}
}

MODIFY
app/Http/Controllers/SpendingController.php
app/Http/Controllers/SpendingController.php
@@ -13,7 +13,7 @@ class SpendingController extends Controller {
public function index(Request $request) {
$user = Auth::user();
- $spendings = $user
+ $spendings = session('space')
->spendings()
->orderBy('happened_on', 'DESC')
->orderBy('created_at', 'DESC')
@@ -23,7 +23,7 @@ class SpendingController extends Controller {
}
public function create() {
- $tags = Tag::where('user_id', Auth::user()->id)->get();
+ $tags = session('space')->tags()->orderBy('created_at', 'DESC')->get();
return view('spendings.create', compact('tags'));
}
@@ -38,7 +38,7 @@ class SpendingController extends Controller {
$spending = new Spending;
- $spending->user_id = Auth::user()->id;
+ $spending->space_id = session('space')->id;
$spending->tag_id = $request->input('tag_id');
$spending->happened_on = $request->input('date');
$spending->description = $request->input('description');

Update SpendingController and DashboardController to work with spendings using space_id