If you want to retrieve the full query that is sent to MySQL, including the actual parameter values, you can use the getBindings() method in conjunction with toSql().
The getBindings() method returns an array of the parameter values bound to the query. By combining this array with the query string obtained from toSql(), you can replace the question marks with their corresponding values to get the complete query.
Here's an example of how you can achieve that:
$query = DB::table('users')
->where('name', 'John')
->where('age', '>', 25);
$sql = $query->toSql();
$bindings = $query->getBindings();
// Replace the question marks with the actual values
$fullQuery = str_replace('?', "'%s'", $sql);
$fullQuery = vsprintf($fullQuery, $bindings);
echo $fullQuery;
In this example, toSql() is used to get the raw SQL query, and getBindings() retrieves the parameter values. The str_replace() function replaces each question mark with '%s', which is a placeholder for the values. Finally, vsprintf() is used to substitute the placeholders with the actual values, resulting in the complete query string.
Keep in mind that this approach is primarily intended for debugging purposes or inspecting the generated queries. When executing queries through Laravel's query builder, parameter binding is automatically handled for you, providing security against SQL injection attacks.