Last active
September 24, 2021 03:50
-
-
Save AhmedHelalAhmed/e8fec1c149b5d8d1ef65edc32177b65f to your computer and use it in GitHub Desktop.
laravel-queries.log
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 DB; | |
use Illuminate\Support\Str; | |
use Illuminate\Support\Facades\Log; | |
use Illuminate\Support\ServiceProvider; | |
class AppServiceProvider extends ServiceProvider | |
{ | |
/** | |
* Bootstrap any application services. | |
* | |
* @return void | |
*/ | |
public function boot() | |
{ | |
$queryCount = 1; | |
DB::listen(function ($query) use (&$queryCount) { | |
$bindings = collect($query->bindings)->map(function ($param) { | |
if (is_numeric($param)) { | |
return $param; | |
} else { | |
return "'${param}'"; | |
} | |
}); | |
Log::info("QUERY (${queryCount}) ====> " . Str::replaceArray('?', $bindings->toArray(), $query->sql)); | |
$queryCount++; | |
}); | |
} | |
} |
tail -f storage/logs/laravel.log
\Illuminate\Support\Facades\Log::channel('single')->debug('hello');
$queryCount = 1;
DB::listen(function ($query) use (&$queryCount) {
$bindings = collect($query->bindings)->map(function ($param) {
if (is_numeric($param)) {
return $param;
} else {
return "'${param}'";
}
});
Log::channel('single')->info("QUERY (${queryCount}) ====> " . Str::replaceArray('?', $bindings->toArray(), $query->sql));
$queryCount++;
});
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Source1 Source2