I'm trying to get my flash message to display.
This is in my routing file
Route::post('users/groups/save', function(){
return Redirect::to('users/groups')->withInput()->with('success', 'Group Created Successfully.');
});
This is in my view
{{ $success = Session::get('success') }}
@if($success)
<div class="alert-box success">
<h2>{{ $success }}</h2>
</div>
@endif
But nothing is working.
When I try this, I get an error Variable $success is undefined. But it actually shows the flash message too.
{{ Session::get('success') }}
@if($success)
<div class="alert-box success">
<h2>{{ $success }}</h2>
</div>
@endif
this should work at localhost and on host and i tried it.
when you set variable or message using
->with()
it doesn't set the variable/message in the session flash, rather it creates an variable which is available in your view, so in your case just use$success
instead ofSession::get('success')
And in case you want to set the message in the session flash the use this
Session::flash('key', 'value');
but remember with session flash the data is available only for next request.Otherwise you can use
Session::put('key', 'value');
to store in sessionfor more info read here
I fixed mine by changing the session driver in config/session.php from array to file !
This works for me
This link describes how to do this http://vegibit.com/flash-messages-in-laravel/
Just tried with laravel 5 - works to me.
i just realized in using the Redirect::to(), when you use the withInput() method, chaining a with() function to pass variables will not work. the only way is either you flash your inputs separately using Input::flash(), and use the with() to pass your variables or you pass your variable via session using Session::flash('key','val') and retrieve in the view via session::get('key').