Created
November 5, 2015 02:39
-
-
Save agarwa13/2b450cd05adcbc467370 to your computer and use it in GitHub Desktop.
Laravel 5.1 Blade File that allows us to conveniently notify our users along with any response. Note we are using notifyjs to prettify our notifications.
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
<script src="{{asset('/vendor/notifyjs/notify.min.js')}}"></script> | |
<script> | |
$(document).ajaxComplete(function(event, xhr, settings){ | |
$( ".log" ).text( "Triggered ajaxComplete handler." ); | |
console.log(xhr.responseText); | |
response = $.parseJSON(xhr.responseText); | |
// Check for Notifications and Display Them | |
if(response.hasOwnProperty('notifications')){ | |
for(var i=0; i< response.notifications.length; i++){ | |
notification = response.notifications[i]; | |
$.notify(notification.message,notification.type); | |
} | |
} | |
}); | |
$(document).ready(function(){ | |
@if(Session::has('notifications')) | |
@foreach(Session::pull('notifications') as $notification) | |
$.notify('{{$notification['message']}}','{{$notification['type']}}'); | |
@endforeach | |
@endif | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment