Created
October 20, 2016 05:49
-
-
Save maxgaurav/a624924f9478e48351ff40339f657fc8 to your computer and use it in GitHub Desktop.
Laravel Flash session helper with various types of messages
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
/** | |
* Function sets the flash message with type | |
* @param string $message [contains message to be displayed] | |
* @param string $type [contains type of message] | |
*/ | |
public static function setFlashMessage ($message, $type = 'success'){ | |
if(session()->has('flashMessages')){ | |
$data = session('flashMessages'); | |
}else{ | |
$data = [ | |
'success' => [], | |
'info' => [], | |
'error' => [], | |
'warning' => [], | |
]; | |
} | |
$data[$type][] = $message; | |
session()->flash('flashMessages', $data); | |
} |
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
{{-- if session has flashMessages --}} | |
@if(session()->has('flashMessages')) | |
{{-- if session has success --}} | |
@if(count(session('flashMessages')['success']) > 0) | |
<div class="callout callout-success"> | |
<h4><i class="fa fa-check"></i> Success</h4> | |
<ul class="unstyled"> | |
@foreach(session('flashMessages')['success'] as $message) | |
<li>{{$message}}</li> | |
@endforeach | |
</ul> | |
</div> | |
@endif | |
{{--end if session has success --}} | |
{{-- if session has error --}} | |
@if(count(session('flashMessages')['error']) > 0) | |
<div class="callout callout-danger"> | |
<h4><i class="fa fa-cross"></i> Errors</h4> | |
<ul class="unstyled"> | |
@foreach(session('flashMessages')['error'] as $message) | |
<li>{{$message}}</li> | |
@endforeach | |
</ul> | |
</div> | |
@endif | |
{{--end if session has error --}} | |
{{-- if session has warning --}} | |
@if(count(session('flashMessages')['warning']) > 0) | |
<div class="callout callout-warning"> | |
<h4><i class="fa fa-warning"></i> Warnings</h4> | |
<ul class="unstyled"> | |
@foreach(session('flashMessages')['warning'] as $message) | |
<li>{{$message}}</li> | |
@endforeach | |
</ul> | |
</div> | |
@endif | |
{{--end if session has warning --}} | |
{{-- if session has info --}} | |
@if(count(session('flashMessages')['info']) > 0) | |
<div class="callout callout-info"> | |
<h4><i class="fa fa-info"></i> Info</h4> | |
<ul class="unstyled"> | |
@foreach(session('flashMessages')['info'] as $message) | |
<li>{{$message}}</li> | |
@endforeach | |
</ul> | |
</div> | |
@endif | |
{{--end if session has info --}} | |
@endif | |
{{-- end if session has flashMessages --}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment