Skip to content

Instantly share code, notes, and snippets.

@jlem
Created July 14, 2016 14:03
Show Gist options
  • Save jlem/fe6eb068763be4c93aa7f39efd2a40ec to your computer and use it in GitHub Desktop.
Save jlem/fe6eb068763be4c93aa7f39efd2a40ec to your computer and use it in GitHub Desktop.
Getting the queries run on model save
<?php
// in service provider
public function boot()
{
// When the saving event fires on any model...
Event::listen(['eloquent.saving: *'], function() {
// Start listening for database queries...
DB::listen(function($query) {
// Then log them.
// It's likely that this callback will fire after `eloquent.saved` fires, which is why you want to listen during
// `saving`, which should be just before the query executes.
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment