I tried to show a flash message when a wrong parameter's given.
I tried doing this:
with session()->flash('error', 'error message.');
and returning the view, but when I put a right parameter in the url I had to load two times in order to let the view show instead of only the error message.
When trying it with(because it was recommended in some SO answers I've found):
session()->now('error', 'error message.');
it worked; I put the correct parameter in the url and had to reload it just one time.
Now I'm wondering what's the difference between these two?
I've read they're both supposed to stay only for one request, but apparently they're not the same...
The flash()
method is used to store data in the session for the next request only. That's why you had to reload your app two times.
On the other hand, now()
is for immediate use, and the data you stored using this method is deleted as soon as you make a new request.
So, which method to use depends basically on when you need to access your data (either current or next request).