Skip to content

Instantly share code, notes, and snippets.

@stevepop
Forked from tomcastleman/DumpSqlServiceProvider.php
Created September 13, 2017 16:25
Show Gist options
  • Save stevepop/efc369b68e025a267995acbe07b06aff to your computer and use it in GitHub Desktop.
Save stevepop/efc369b68e025a267995acbe07b06aff to your computer and use it in GitHub Desktop.
Laravel Query Builder Dump SQL Macro
<?php
namespace App\Providers;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\ServiceProvider;
class DumpSqlServiceProvider extends ServiceProvider
{
public function boot()
{
}
public function register()
{
Builder::macro('dumpSql', function ($die = false) {
/** Builder $this */
dump($this->toSql());
$method = $die ? 'dd' : 'dump';
$method($this->getBindings());
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment