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

Lars-Janssen's avatar

Laravel ajax call set session variable correctly

Hi,

Through an ajax call with axios I set a session variable in Laravel 5.5:

session()->put('can_visit', true);

However when I check in a next get request (not with ajax) if that variable exists:

return session()->has('can_visit');

Result is always false why is that? Is there a better way?

Thx

0 likes
4 replies
ejdelmonico's avatar

I believe you need to store as a string so session()->put('can_visit', 'true')

ejdelmonico's avatar

You are correct, I just looked it up and the value is mixed with a default of null. The has method returns true if the value is present and is not null.

Please or to participate in this conversation.