I have a following code in my posts.create
action.
// ...
return redirect(route('posts.index'))->with('flashMessage', 'test');
// ...
I expect $flashMessage
variable to be available in the posts.index
view, however, it is not. What am I doing wrong?
P.S
I don't want to set the flash message using Session::flash('flashMessage', 'test')
, because it won't work in case of json responses.
in redirect you have to pass url not route name add the following code to your blade page
@if(Session::has('flashMessage'))
<div class="alert alert-danger">
{{ Session::get('flashMessage') }}
</div>
@endif