Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

KNietzsche's avatar

Session ..difference Axios/Laravel

I have a Route post that I call from Vuejs component with Axios

Route::post('/sessionsaveparam', function(Request $request) {

 $param_name = request()->input('param_name');
     $param_value = request()->input('param_value');

       session()->put($param_name, $param_value );
       session()->put("titi", $param_value );

       $request->session()->put("titi", $param_value);

       // session([$param_name]) = $param_value ;
    return response(['status' => "Param session".$param_name."saved",
              'param_name' => $param_name,
              'session' => session()->all(),
              'param_value' =>session()->get($param_name)
              // 'param_value' => session()->get($param_name)
               ], 200);
})->name('sessionsaveparam');

this returns

status: "Param sessionproject_idsaved", param_name: "project_id",…}
param_name
:
"project_id"
param_value
:
11
session
:
{_token: "k57yFyGOtARPxKZLdbivOlx5aKaLWnQEfbAhJsA0", _flash: {old: [], new: []}, url: [],…}
login_web_59ba36addc2b2f9401580f014c7f58ea4e30989d
:
3
project_id
:
11
titi
:
11
topmenu
:
"Projets"
url
:
[]
_flash
:
{old: [], new: []}
_previous
:
{url: "http://noel1.localhost/project"}
_token
:
"k57yFyGOtARPxKZLdbivOlx5aKaLWnQEfbAhJsA0"
status
:
"Param sessionproject_idsaved"

and then I have another standard route GET

Route::get('test', function(){ 
  dd(session()->all());
});

and the result is

array:8 [▼
  "_token" => "k57yFyGOtARPxKZLdbivOlx5aKaLWnQEfbAhJsA0"
  "_flash" => array:2 [▶]
  "url" => []
  "_previous" => array:1 [▶]
  "login_web_59ba36addc2b2f9401580f014c7f58ea4e30989d" => 3
  "topmenu" => "Projets"
  "project_id" => null
  "titi" => null
]

so question is...why the result from session()->get() is different when I call with axios, and why I cannot get the correct session values with a standard route ? Idea is I would like to save the last project id that I used to restore data when I come back to the page.

Do I need to use a database as a driver to save the session ? or Redis ? for the moment I use normal file driver.

Did I miss something ?

Thanks for your answers...

0 likes
3 replies
KNietzsche's avatar

no idea ? I still have the problem and am not able to solve it...seems very strange...to resume, when I call a route or controller and try to save a data (trhough axios and a post request) into a session, everything looks correct, but if I try to read with a session->get... after, the value is wrong or not filled...

Sinnbeck's avatar

I have this exact issue. How did you solve it?

Please or to participate in this conversation.