Laravel - insertGetId显示参数不匹配错误

时间:2014-11-01 02:12:26

标签: php laravel laravel-4

我想知道是否有人可以帮我解决错误。

我有以下代码:

$suburbInsert = array();
$suburbInsert[] = array(

    'name' => $postalCode . ' ' . $suburbName,
    'suburb_name' => $suburbName,
    'pcode' => $postalCode

);

$suburbID = DB::table('suburbs')->insertGetId( $suburbInsert );

当我运行它时,我收到以下错误

{"error":{"type":"ErrorException","message":"preg_replace(): Parameter mismatch, pattern is a string while replacement is an array","file":"\/var\/www\/laravel\/vendor\/laravel\/framework\/src\/Illuminate\/Support\/helpers.php","line":990}}

非常感谢任何帮助

1 个答案:

答案 0 :(得分:1)

您正在创建$suburbInsert作为数组数组。

而不是:

$suburbInsert = array();
$suburbInsert[] = array(
    ...
);

只是做:

$suburbInsert = array(
    ...
);