laravel操作数据库出现如上报错,看了半天方法没有发现问题,传入的是个数组,为啥会报错,查看日志
Stack trace:
#0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'preg_replace():...', '/Users/...', 685, Array)
#1 /Users/code/php/xxx/vendor/laravel/framework/src/Illuminate/Support/helpers.php(685): preg_replace('/\\?/', Array, 'insert into `kp...', 1)
#2 /Users/code/php/xxx/vendor/laravel/framework/src/Illuminate/Database/QueryException.php(56): str_replace_array('\\?', Array, 'insert into `kp...')
#3 /Users/code/php/xxx/vendor/laravel/framework/src/Illuminate/Database/QueryException.php(39): Illuminate\Database\QueryException->formatMessage('insert into `kp...', Array, Object(PDOException))
看日志中有字符串替换函数,突然想到报错方法入参数组中有一项是个数组,将该数组改为字符串,程序正常执行
$input = array(
'name' => 'name',
'cause' => $cause
);
其中cause是个数组,将其改为 即可
'cause' => json_encode($cause)