问题
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 thereturn view()
来源:https://stackoverflow.com/questions/42417865/how-to-return-view-with-flash-message