edvinaskrucas / notification

Notification package for Laravel
MIT License
526 stars 98 forks source link

FR: save notifications over multiple redirects #71

Open judgej opened 8 years ago

judgej commented 8 years ago

A notification will normally be available on the next page, and will subsequently be removed from the session after that.

An instant notification will appear on the current page and will not even make it into the session.

What does not seem to be covered, is saving the notifications for displaying several pages from now. For example, I set a notification, then redirect to the next page. That next page does a check which means it also needs to immediately redirect to another page. The notifications are lost in that second redirect. There needs to be a way to tell this package to hold on to the messages just one more page. Maybe there is a way, and I am just missing it?

judgej commented 8 years ago

Core Laravel flash messages can be kept alive for another page using this method:

$request->session()->reflash();
// or
$request->session()->keep(['username', 'email']);

So something like Notification::reflash() would be the kind of thing I'm looking for.

judgej commented 8 years ago

So if I understand how this package works, the notifications are put into the notifications (by default) session key. The middleware pulls these notifications out of this session key, and puts them into the Notifications singleton in the laravel container. It then immediately removes them from the session. That happens before it gets to the controller that makes the choice about whether it gives the user a page (with the notifications displayed) or needs to do a further redirect, taking the current notifications with it.

So if a controller redirect needs to take the previous page notifications with it on a redirect, it needs to move the notifications in the Notifications singleton back into the session, possibly merging them with additional notifications that the redirecting page may have generated. Does that sound about right?

judgej commented 8 years ago

On a kind of very similar vein, I am finding the notification messages are getting lost on a browser redirect. In an iframe, I am handling 3D Secure. On success in the iframe, I am setting a Notification message, then returning a single self-submitting GET form with a target of _top to break out of the iframe. On the next page, there are no Notifications. The page the form auto-submits to is the very next page the browser sees, so I don't know where the Notifications go to. If I do a server redirect in the iframe (going to the same next page, but not via a self-submitting form) then the Notifications are all displayed. It's a bit of a mystery.

Are the Notifications perhaps only written to the session on a redirect?

Edit: on a hunch, I switched off the debug bar, and the notifications started working again. Unlike doing a server redirect, displaying an auto-submit form also displayed the debug bar along with the form. The debug bar does an AJAX call which then consumes the notifications on that page, so when the form takes the browser to the next page, there are no notifications left to display. I'll raise this with the debug bar, to see if there is some way to disable it for specific pages always. That solves the additional related issue at least.