BMO-VIK liked a comment+100 XP
2mos ago
Warning:
If it seems like there are no ideas stored in session at 15:00, it might be happening because you tried to register the GET route like this:
Route::view('/', 'idea', [
'ideas' => session('ideas', []),
]);
Instead, use the approach from the video and register the route under Route::get()
Brief explanation:
Route::view is trying to be efficient, so it loads its arguments only once at the very beginning.
From then on, whenever we try to access the route again, Route::view will always use the original session value instead of the updated one.
If you tried to render the session variable inside the blade view, you would always see the default value - in this case, an empty array, because that's what was set at:
'ideas' => session('ideas', []),
As Jeffrey mentioned in an earlier lesson (4), Route::view is meant for simpler, mostly static pages. Loading pages this way is more efficient, but it has downsides, as you can see in this example.
BMO-VIK wrote a reply+100 XP
5mos ago