Create RefreshSpaceRelations middleware for refreshing relations of selected space that's stored in session
MODIFY
app/Http/Kernel.php
app/Http/Kernel.php
@@ -34,7 +34,8 @@ class Kernel extends HttpKernel
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
- \App\Http\Middleware\SetLocale::class
+ \App\Http\Middleware\SetLocale::class,
+ \App\Http\Middleware\RefreshSpaceRelations::class
],
'api' => [

ADD
app/Http/Middleware/RefreshSpaceRelations.php
+<?php
+
+namespace App\Http\Middleware;
+
+use Closure;
+
+class RefreshSpaceRelations {
+ public function handle($request, Closure $next) {
+ if ($request->session()->has('space')) {
+ $request->session()->get('space')->load('tags', 'earnings', 'spendings', 'recurrings');
+ }
+
+ return $next($request);
+ }
+}

Create RefreshSpaceRelations middleware for refreshing relations of selected space that's stored in session