Skip to content

Instantly share code, notes, and snippets.

Avatar

Vitor Faiante vitorf7

View GitHub Profile
@arodbits
arodbits / binder.php
Last active Jan 20, 2020
Combine binding values into a raw SQL query in Laravel. Debugging in Laravel.
View binder.php
<?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}'";
You can’t perform that action at this time.