PHP code example of loburets / laravel-query-printer

1. Go to this page and download the library: Download loburets/laravel-query-printer 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/ */

    

loburets / laravel-query-printer example snippets


// Enable query log
\DB::enableQueryLog();

// Use whatever queries you want to debug:
User::where('email', '[email protected]')->where('verified', true)->first();
User::where('id', '<', '5')->get();

// See what the queries were executed
\QueryPrinter::printQueryLog();

'QueryPrinter' => Loburets\LaravelQueryPrinter\Facade::class,

    // Build your query, but don't call ->first(), ->get() etc. So it is an instance of the Query Builder here:
    $query = \Model::where()->join()->etc();

    // Print the generated SQL
    \QueryPrinter::print($query);

    // Enable the Query log:
    \DB::enableQueryLog();

    // Do any actions which you want to be logged:
    $results = \Model::where()->join()->etc()->get();

    // Print all the executed queries
    \QueryPrinter::printQueryLog();