laravel-query-monitor
laravel-query-monitor copied to clipboard
explode() expects parameter 2 to be string, array given
trafficstars
On v1.0.1 and 1.0.2 of the library you can receive this error in certain situations where the SQL being passed to the listener is missing.
Example of data being passed into the listener:
# Debug:{"sql":{},"bindings":[],"time":362.02,"connection":{},"connectionName":"mysql"}
The error that occurs:
ErrorException
explode() expects parameter 2 to be string, array given
at vendor/laravel/framework/src/Illuminate/Support/Str.php:483
479▕ * @return string
480▕ */
481▕ public static function replaceArray($search, array $replace, $subject)
482▕ {
➜ 483▕ $segments = explode($search, $subject);
484▕
485▕ $result = array_shift($segments);
486▕
487▕ foreach ($segments as $segment) {
As a quick fix, inside of ListenQueries I replaced
$sql = Str::replaceArray('?', $normalizedBindings, $query['sql']);
with
$sql = !empty($query['sql']) ? Str::replaceArray('?', $normalizedBindings, $query['sql']) : null;