Created
September 13, 2017 12:24
-
-
Save tomcastleman/153020d0b1b4a77ae09f14bd70b4ceb1 to your computer and use it in GitHub Desktop.
Laravel Query Builder Dump SQL Macro
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 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
Usage: