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

kevinm40's avatar

Event firing problem (or just trying to place a cookie on a page)

After a user has just registered, I need to place a cookie on the /home page of the app, but it must only appear once, on succesful registration.

The approach I have used is to have setting in my app/config of 'justRegistered' => 'false',, then create an event attached to EventServiceProvider with

'Laravel\Spark\Events\Auth\UserRegistered' => [
            'Laravel\Spark\Listeners\Subscription\CreateTrialEndingNotification',
            'App\Events\SendWelcomeEmail',
            'App\Events\JustRegisteredTracking',
        ],

the handle of the event has:

    public function handle(UserRegistered $userRegistered)
    {
        \Config::set('app.justRegistered', 'true');
    }

which changes the 'false' to 'true'

lastly, in my blade layout I have the following

 @if (Config::get('app.justRegistered')=='true')
// some stuff
@endif

The problem is that the setting doesn't change, and stays at false. I have checked that the event is firing correctly on registration, which it seems to be, but the blade template is not picking up on the change.

Any ideas why? Or a simpler approach?

0 likes
3 replies
thoasty's avatar

Use

return redirect()->with(array $data);
kevinm40's avatar

Thanks. You mean in the event handle? I am getting an Method with does not exist error when I try this.

kevinm40's avatar

I found a solution (in my event handle):

    public function handle(UserRegistered $userRegistered)
    {
        session()->flash('justRegistered', 'true');
    }

I then just test for that in the blade template:

 @if (Session::get('justRegistered')=='true')
    // stuff
 @endif

Please or to participate in this conversation.