Last active
December 20, 2024 19:00
-
-
Save gvsrepins/f677e3f8d29a34028188442e70e60f98 to your computer and use it in GitHub Desktop.
Log all executed queries in a Laravel application (check storage/logs/laravel.log file)
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 | |
namespace App\Providers; | |
use Illuminate\Support\ServiceProvider; | |
use Illuminate\Support\Facades\DB; | |
use Illuminate\Support\Facades\Log; | |
class AppServiceProvider extends ServiceProvider | |
{ | |
/** | |
* Bootstrap any application services. | |
*/ | |
public function boot(): void | |
{ | |
DB::listen(function($query) { | |
Log::info( | |
$query->sql, | |
[ | |
'bindings' => $query->bindings, | |
'time' => $query->time | |
] | |
); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment