If I immediately dd the session it shows the new value. But in another place, it shows the old value means not saving. I have been facing this issue with every Laravel project.
I tried with all session drivers, redis, array, file and databse. Anybody, please give a permanent solution of this issue.
<?php
use Illuminate\Support\Facades\Session;
class XyController extends Controller{
public function X()
{
Session::put('currency', $currency); /* to set session */
Session::get('currency'); /* to read session data */
}
}
?>
If you refresh page ???????? Is anything passed to $currency?
A modern web app shouldn't be refreshing a page. Rather on each request go through proper view and route to properly pass the necessary data along.
If you are using ajax, DO NOT use session with ajax.
I use sessions often in ver 5.5, and never had a problem.
Once something saved in the session it should be persistent. Yes of course on refreshing it should be there. I am not using ajax.
Example:
Goto Fiverr.com on the bottom right side there is currency dropdown. Change that and see, the page refreshes and sets that currency in session.