Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return view with flash message?

What i need is this:

return view('protected.standardUser.includes.documents',compact('documents'))->with('successMsg','Property is updated .');

The i could use it like this:

  @if(Session::has('successMsg'))
    <div class="alert alert-success"> {{ Session::get('successMsg') }}</div>
  @endif

Any suggestion?

like image 963
None Avatar asked Feb 23 '17 14:02

None


People also ask

What is session flash message?

Session:Flash Tag Flash data is session data that is only kept for a single request. It is most often used for success/failure messages that automatically disappear after a page refresh.

What is flash message in laravel?

A flash message is used to communicate back to the user of the website or application that an event has taken place. Often times you'll see a redirect with flash message. This may be something the user intended to do, or it might be something that is just informational.


2 Answers

I order to use session stored flash messages, need to use following code into route method.

 $request->session()->flash('successMsg','Saved succesfully!'); 

and then do

 @if(Session::has('successMsg'))
    <div class="alert alert-success"> {{ Session::get('successMsg') }}</div>
  @endif

that's it

like image 111
ARUN Madathil Avatar answered Sep 22 '22 15:09

ARUN Madathil


I'm new in Laravel and I was facing the same issue... I just tried as below::

\Session::flash('flash','Message info');

And it works!!

like image 40
Daniel Azamar Avatar answered Sep 21 '22 15:09

Daniel Azamar