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

theFinalArbiter's avatar

Use session to check if visitor has subscribed to newsletter, if they have don't show subscription section

I have a page with no user system. However I do allow for people to subscribe to a newsletter. I have a bar on top of the page where I display a section for the user to subscribe to the newsletter. I know want to make it so that when a user has subscribed they wont no longer be disturbed by this bar (in this session)..

My thoughts is that when the user subscribes I assign something to my session() in my controller when the user subscribes.

kind of like this;

session('subscribed', true);

Then each time when I load a blade I check

@if(session()->subscribed === false)
    include('partials.subscribeForm');
@endif

But what I am not being able to figure out is the syntax for this?

Is there anyone out there to help?

0 likes
2 replies
Wouter.D's avatar

Something like this?

Set the session:

$request->session()->put('subscribed',true);

Retrieve the session:

$request->session()->get('subscribed');

Please or to participate in this conversation.