4

Normally in Laravel 4.2 when we create flash message by

Session::flash('message','This is flash message');

and display it by

Session::get('message'); 

It will disappear when we refresh the page.

The question is how could we set the display time of this flash message?

(For example: After 3 seconds, this message will disappear!).

Sanshayan
  • 39
  • 1
  • 1
  • 10
Alex
  • 359
  • 3
  • 15
  • 1
    You'll need to do this using JavaScript. Essentially, attach a `setTimeout` event to the flash message's parent element that hides or removes the text after a given amount of time. – Stuart Wagner May 08 '15 at 04:00

2 Answers2

7

This is how you would do it.

$('div.alert').delay(3000).slideUp(300);

change alert to whatever class you are using to display error message.

StealthTrails
  • 2,281
  • 8
  • 43
  • 67
  • 1
    Why would you even suggest using jQuery? You don't even say you are using jQuery here. The OP clearly is missing fundamentals of web development, this answer mustn't have helped that much on its own... – xyhhx Apr 27 '16 at 04:24
  • 1
    @Martin first of all this is the only way JS or jQuery, if you know other methods please post. And secondly you could have edited the answer to add "using jQuery" or something else instead of just posting a lame comment. – StealthTrails Apr 27 '16 at 05:44
  • Do you want me to pack you a lunch in the morning too, kiddo? – xyhhx Apr 27 '16 at 12:52
  • 2
    Adam is correct.. It can be done only thro JS or jQuery. – Nevermore May 03 '16 at 12:20
  • 1
    @Martin I like your trashtalk. However, you can refer to this link https://github.com/laracasts/flash for more clarification. – Nevermore Dec 08 '16 at 07:22
4

You cant do it with PHP. What you could to, is create a javascript that will hide all elements with a given class (whatever is the class of this flash message) after set amount of time from when the page is loaded.

Pawel Bieszczad
  • 12,925
  • 3
  • 37
  • 40
  • Thank you for your answer. In case that I want to refresh the flash data every time I click on an button? What should I do with javascript? I've tried with javascript into an IF clause! It done well with refreshing the flash data. But after refresh it move to the top of the page. Can I still on the position that I click on the button? – Alex May 12 '15 at 15:36