how to display query in laravel code example
Example 1: print last sql query laravel
DB::enableQueryLog();
dd(DB::getQueryLog());
Example 2: show query in laravel
Use the toSql() method on a QueryBuilder instance.
DB::table('users')->toSql()
Example 3: laravel get query in normal sql without bindings
public static function getEloquentSqlWithBindings($query)
{
return vsprintf(str_replace('?', '%s', $query->toSql()), collect($query->getBindings())->map(function ($binding) {
$binding = addslashes($binding);
return is_numeric($binding) ? $binding : "'{$binding}'";
})->toArray());
}