In my Laravel 4 project, I am trying to set a flash message when redirecting, like so:
return Redirect::route('main')->with('flash', 'Message here.');
(I looked at the following: Laravel 4 - Redirect::route with parameters).
The redirect happens properly. In my 'main' view I've got this code to display the flash message:
@if (Session::has('flash'))
<div class="flash alert">
<p>{{ Session::get('flash') }}</p>
</div>
@endif
But it doesn't work: Session::get('flash')
returns an array, not a string. If I insert a call to var_dump(Session::get('flash'))
, I get this output:
array (size=2)
'new' =>
array (size=0)
empty
'old' =>
array (size=1)
0 => string 'flash' (length=5)
What is happening? It seems like fairly straightforward code...
When you redirect with data, the data you save will be 'flashed' into session (meaning it will only be available during the next request, see: http://laravel.com/docs/session#flash-data).
I would be wary of using 'flash'
as a flash data key, as Laravel stores its flash data in a key already with a name of 'flash'
. Try changing your name to something else. You may be confusing Laravel's Session::get
as to where it should be attempting to load the data from.
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