Skip to content

Instantly share code, notes, and snippets.

@agarwa13
Created November 5, 2015 02:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save agarwa13/2b450cd05adcbc467370 to your computer and use it in GitHub Desktop.
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.
<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