傳遞給 Illuminate\Database\Grammar::parameterize() 的參數 1 必須是數組類型,給定字符串 - 當嘗試通過 eloquent 插入數據庫數據時

阿德里安康斯坦丁

我正在嘗試使用 Laravel 的 Eloquent ORM 將一些記錄插入到數據庫中。數據存儲在一個看起來像這樣的數組中(數組中有多個元素)

我循環遍歷的初始數組如下所示

array:1 [▼
  "Product" => array:4416 [▼
    0 => array:9 [ …9]
    1 => array:9 [ …9]
    2 => array:9 [ …9]
    3 => array:10 [ …10]
---------------------------------------------------------------------
array:9 [▼
  "ProductCode" => "EWS1025CAM"
  "Vendor" => "ENGENIUS"
  "ProductType" => "Security - Surveillance Indoor Camera"
  "ProductCategory" => "Other"
  "ProductDescription" => "Managed AP-CAM Indoor Dual Band 11ac 2T2R 300+867Mbps 2MP dome 4mm IR20m PoE.af μSDHC (Access point - Camera, Power Adapter (12V/1.5A), T-rail mounting kit, mou ▶"
  "Image" => "https://www.it4profit.com/catalogimg/wic/1/EWS1025CAM"
  "ProductCard" => "https://content.it4profit.com/itshop/itemcard_cs.jsp?ITEM=171208071213009310&THEME=asbis&LANG=ro"
  "AttrList" => array:1 [▶]
  "Images" => array:1 [▶]
]

我正在遍歷它並插入這樣的值

foreach ($phpDataArray['Product'] as $key => $value)
        {
                $insert = new FurnizorProduse();
                $insert->product_id = $value['ProductCode'];
                $insert->product_data = json_encode($value);
                $insert->date = new \DateTime();
                $insert->module_id = 58;
                $insert->save();
        }

即使數據正確插入到數據庫中,我也得到“傳遞給 Illuminate\Database\Grammar::parameterize() 的參數 1 必須是數組類型,給定字符串”。導致這種情況的代碼行$insert->product_id = $value['ProductCode'];就好像我用 $value['ProductCode'];整數替換了比方說,沒有更多的錯誤。有任何想法嗎 ?謝謝 !

約翰尼小丑

在您的迭代之一中:

$phpDataArray['Product'],你沒有:$value['ProductCode'],這是我的假設。

試著做:

if(is_array($value) && isset($value['ProductCode'])) {
$insert = new FurnizorProduse();
...
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章