How to return view with flash message?

非 Y 不嫁゛ 提交于 2020-05-13 06:50:05

问题


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?


回答1:


It looks like you're mixing two different ways of passing data to a view, which I'm guessing is the problem. The documentation seems to indicate it's a one or the other type situation. You also seem to be mixing up view()->with() and redirect()->with(), which work differently. Try this:

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

And

@if(!empty($successMsg))
  <div class="alert alert-success"> {{ $successMsg }}</div>
@endif



回答2:


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




回答3:


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!!




回答4:


This works for me!

return view('protected.standardUser.includes.documents',compact('documents'),
['successMsg'=>'Property is updated .']);

just remove the with() and pass it in the return view()



来源:https://stackoverflow.com/questions/42417865/how-to-return-view-with-flash-message

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!