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)