I'm encountering a very strange issue and couldn't find anything about it. I'm trying a very simple thing, using a flash message in Laravel to display a message to the user if a condition didn't met.
Basically this is the controller code i'm using:
Session::flash('error', 'error message');
return redirect()->back();
// this didn't work either
// return redirect()->action('Controller@method', $var)->with('error', ['error message']);
The thing is, it IS working when I var_dump the session in the view, but not without it. This is the view:
{{ Session::get('error') }} // does not work
{{ dd(Session::get('error')) }} // works!
It is a very simple thing, but I don't know why it goes wrong.
Any helpers around? :) Thanks!
You shall debug in this way
Clear all the files in your sessions folder
In your controller you can create flash message using any of the given two ways
Session::flash('error', 'error message');
return redirect()->back();
or
return redirect()->action('Controller@method', $var)->with('error', ['error message']);
Then in your blade
@if (Session::has('error'))
<div class="alert alert-info">
{{ Session::get('error') }}
</div>
@endif
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With