You can easily implement what this package does by adding something like this to DatabaseServerProvider::boot()
:
if (env('APP_DEBUG')) {
DB::listen(function (QueryExecuted $query): void {
$sql = str_replace("\n", ' ', $query->sql);
$bindings = \Safe\json_encode($query->bindings);
\Safe\file_put_contents(
filename: storage_path('logs/query.log'),
data: "SQL: {$sql} ||| Bindings: {$bindings} ||| Time: {$query->time}ms\n",
flags: FILE_APPEND,
);
});
}
Log database queries to an output channel of your choice.
composer require mll-lab/laravel-query-log
That's it. Laravel's package discovery will automatically kick in.
All database queries are written to storage/logs/query.log
by default.
If you want to change the location, publish the configuration file:
php artisan vendor:publish --tag=query-log-config