Skip to content

Instantly share code, notes, and snippets.

@vitorf7 vitorf7/binder.php forked from thonyx/binder.php
Created Aug 14, 2019

Embed
What would you like to do?
Combine binding values into a raw SQL query in Laravel. Debugging in Laravel.
<?php
//example:
$query = Foo::where('id', '=', 1)->where('name', '=', 'bar');
//would produce the following raw query:
//select * from foo where id = ? and name = ?;
dd(vsprintf(str_replace('?', '%s', $query->toSql()), collect($query->getBindings())->map(function($binding){
return is_numeric($binding) ? $binding : "'{$binding}'";
})->toArray()));
//result:
//select * from foo where id = 1 and name = 'bar';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.