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
Session:Flash Tag Flash data is session data that is only kept for a single request. It is most often used for success/failure messages that automatically disappear after a page refresh.
Summary. Flashing data to the session stores short-lived data and can display it in the application. It is usually used to display status after an action. RELATED TAGS. laravel.
This works for me
@if(Session::has('success'))
<div class="alert-box success">
<h2>{{ Session::get('success') }}</h2>
</div>
@endif
if you are using bootstrap-3 try the script below for Alert Style
@if(Session::has('success'))
<div class="alert alert-success">
<h2>{{ Session::get('success') }}</h2>
</div>
@endif
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 of Session::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 session
for more info read here
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