0

I have a newly installed laravel application (version 8.36.2) and the session storing is not working, is it a release issue?

I made my code step-by-step by the laravel documentation, and the stored session is lost, if i open a new route. For example.:

My base controller.:

    public function setSession(Request $req)
    {
        $req->session()->put('name', 'Jennifer');
        echo "Saved";
    }

    public function getSession(Request $req)
    {
        if ($req->session()->has('name')) {
            echo $req->session()->get('name');
        } else {
            echo "Empty the session";
        }
    }

My web.php

Route::get('set-session', [LoginController::class, 'setSession'])->name('session.set');
Route::get('get-session', [LoginController::class, 'getSession'])->name('session.get');

The storing is working, so if i dd() the session after the setSession() I can see the name property, but, if I open the /get-session route, the name session property is null.

I also tryed with the session(['name' => Jennifer]) facade, but it also doesn't work.

Can someone help me, why?

Giacomo M
  • 4,450
  • 7
  • 28
  • 57
  • I created a new laravel project and copy and pasted your code and it worked properly, I saw "Jennifer" when I visited get-session. – Alex Harris Apr 11 '21 at 15:48
  • Good to hear that. Thank you, that you try it. According to them, definitely some environmental setting is wrong on my computer. I will continue the investigation because the Authentatication also doen't work. – Balázs Szedlacsek Apr 11 '21 at 16:09
  • Try this: https://stackoverflow.com/a/63760186/1561929 – Alex Harris Apr 11 '21 at 16:17
  • unfortunately doen't work. I think the problem, that on every request new session file generated under storage/framework/sessions. So If i refresh the /get-session page 5 time, 5 different session file apper. This is not normal operation, right? – Balázs Szedlacsek Apr 11 '21 at 16:31
  • Finally I find the problem. On the session.php the domain have to be NULL or different than the APP_URL, because of if there is same, the session doen't work. Very-very thank you for your support. – Balázs Szedlacsek Apr 11 '21 at 16:37

0 Answers0