eloquent to sql with bindings code example
Example 1: print last sql query laravel
DB::enableQueryLog();
dd(DB::getQueryLog());
Example 2: eloquent to sql with bindings
$query = DB::table('table')->whereIn('some_field', [1,2,30]);
$sql = $query->toSql();
$bindings = $query->getBindings();
Example 3: eloquent to sql with bindings
\App\User::where('age', '18')->dump();
\App\User::where('age', '18')->dd();
Example 4: eloquent to sql with bindings
public static function getQueries(Builder $builder)
{
$addSlashes = str_replace('?', "'?'", $builder->toSql());
return vsprintf(str_replace('?', '%s', $addSlashes), $builder->getBindings());
}