Created
July 14, 2016 14:03
-
-
Save jlem/fe6eb068763be4c93aa7f39efd2a40ec to your computer and use it in GitHub Desktop.
Getting the queries run on model save
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
<?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