PHP code example of mll-lab / laravel-query-log

1. Go to this page and download the library: Download mll-lab/laravel-query-log library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mll-lab / laravel-query-log example snippets


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,
        );
    });
}