Created
July 6, 2016 14:21
-
-
Save shishircse06/c03b212fa26e43f27308beef16c5b85f to your computer and use it in GitHub Desktop.
Laravel flash message
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Session::flash('message', 'This is a message!'); | |
Session::flash('alert-class', 'alert-danger'); | |
In view: | |
@if(Session::has('message')) | |
<p class="alert {{ Session::get('alert-class', 'alert-info') }}">{{ Session::get('message') }}</p> | |
@endif | |
OR: | |
In controller: | |
Session::flash('alert-danger', 'danger'); | |
Session::flash('alert-warning', 'warning'); | |
Session::flash('alert-success', 'success'); | |
Session::flash('alert-info', 'info'); | |
Session::flash('message', 'This is a message!'); | |
In View: | |
<div class="flash-message"> | |
@foreach (['danger', 'warning', 'success', 'info'] as $msg) | |
@if(Session::has('alert-' . $msg)) | |
<p class="alert alert-{{ $msg }}">{{ Session::get('message') }}</p> | |
@endif | |
@endforeach | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment