PHP code example of dietercoopman / laravel-showsql

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

    

dietercoopman / laravel-showsql example snippets

 
# With the Eloquent Builder

Menu::showSql()->get();

Menu::whereId(1)->showSql()->get();

Menu::whereHas('status')->showSql()->get();

# With the Query Builder

DB::table('menus')->where('id', '=', 10)->showSql()->get();

DB::table('menus')->join('statuses', 'statuses.id', '=', 'menus.status_id')
                 ->showSql()
                 ->get();

# With a callback 

$callback = function(string $sql){
  Log::info($sql);
};

DB::table('products')->where('id', '=', 1)->showSql($callback)->get();


return [
    'to' => [
        'telescope' => false,
        'ray' => true,
        'clockwork' => true,
        'debugbar' => true,
        'log' => false,
        'browser' => false,
    ]
];

shell
php artisan vendor:publish --tag=showsql-config