如何return查看快闪消息?

How to return view with flash message?

我需要的是这个:

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

我可以这样使用它:

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

有什么建议吗?

您似乎在混合使用两种不同的方式将数据传递给视图,我猜这就是问题所在。 The documentation 似乎表明这是一种或另一种情况。您似乎还混淆了 view()->with()redirect()->with(),它们的工作方式不同。试试这个:

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

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

我为了使用session存储flash消息,需要使用下面的代码进入route method

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

然后

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

就是这样

这对我有用!

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

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

我是 Laravel 的新人,我遇到了同样的问题...我只是尝试如下::

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

而且有效!!