edvinaskrucas / notification

Notification package for Laravel
MIT License
525 stars 99 forks source link

Redirecting and passing on messages #54

Closed judgej closed 9 years ago

judgej commented 9 years ago

Firstly this is a great package - thank you for that.

I suspect what I am trying to do is supported, but I can't quite see how. The situation is this:

I have a landing page, which registers a notification message then redirects to a survey. That survey then does another redirect to take the user to the next page of that survey. In that second redirect, the initial notification is lost. I'm guessing the messages are cleared from the session on each page load, regardless of whether they are displayed or not.

So is there a way to pass the messages on to the next page? i.e. a route that contains only a redirect is given a notification from the previous page, which it then needs to pass on to the final (third) page.

edvinaskrucas commented 9 years ago

Hey!

This is related to Laravel sessions. You can check this Session::reflash();, it might be helpful.

judgej commented 9 years ago

I feel like it is a Notification::reFlash() or something to that effect, which I need. It would take all the current notifications that have been pulled from the session, and push them all back into the session where they came from.

judgej commented 9 years ago

Ha - posted at the same time :-)

judgej commented 9 years ago

Yes, Session::reflash() does the job , thank you.

edvinaskrucas commented 9 years ago

This function might be helpful, but if reflashing session will help, let me know and close this issue :)

judgej commented 9 years ago

What happens in the session is a bit of a mystery to me. Do these notifications ride on top of transient session variables that Laravel core already handles? I guess it must do if Session::reflash() works here. I think it can be closed, but let me know if there are any knock-on effects for reflashing everything that you can think of - it really depends on how separate these notification messages are in the session from other messages that may be flashed in other ways and which I may or may not want passed on. (probably close it :-)

edvinaskrucas commented 9 years ago

There will be side effect if You don't want some data to be reflashed, as reflash will reflash all messages and other flashed stuff.

judgej commented 9 years ago

Would Session::keep('notifications-or-whatever-it-is-called'); be an approach that could be used to reflash just the notifications for this package?

judgej commented 9 years ago

Okay, after some digging, I think it may be a useful method to have in this package. Just reflashing a single info message, I confirmed it worked like this:

Session::keep('notifications_containers', 'notifications_default_1');

Obviously that will only work in a very specific use-case, but it shows how it could work. If there were a Notification::reflash() and/or Notification::keep(which-to-keep) method, that would be great.

For now I'm just reflashing everything, as that works for me right now. If you need a pull request (assuming you want this as a feature) then it will probably be at least a few weeks before I can get down to looking at the internals.

I'll leave it with you to decide what you want to do, but I'm happy to help.

edvinaskrucas commented 9 years ago

Hey, thanks for your suggestion. I am thinking to add some params to a message which identifies if message needs reflash if not used, or something like that. But have no time for this at the moment, will come back to this in few weeks.