我有错误“SQLSTATE[42S22]:未找到列:1054‘字段列表’中未知列‘0’”

问题描述 投票:0回答:1

当我更新表时,laravel 坏了 在另一个网站上,相同的代码运行良好


                        $flatBuilder = Lot::where('lotid', $lotid);
                        $arFlat = $flatBuilder->first();

                        $arFields[] = array(
                            'lotid' => $lotid,
                            'lot' => $lot,
                            'type' => $type,
                            'status' => $status,
                            'price' => $price,
                            'pricesq' => $pricesq,
                            'area' => $area,
                            'floor' => $floor,
                            'height' => $height
                        );

                        if ($arFlat) {
                            $flatBuilder->update($arFields);
                        } else {
                            Lot::create($arFields);
                        }

更新不起作用... 我的错误在哪里? 需要帮助!

laravel eloquent
1个回答
0
投票

由于您已经将数组值分配给

$arFields
,因此无需将其初始化为空数组。将您的代码更改为此(从 $
[]
中删除
$arFields

$arFields = array(
    'lotid' => $lotid,
    'lot' => $lot,
    'type' => $type,
    'status' => $status,
    'price' => $price,
    'pricesq' => $pricesq,
    'area' => $area,
    'floor' => $floor,
    'height' => $height
);

结果:

array:9 [
  "lotid" => 1
  "lot" => 1
  "type" => 1
  "status" => 1
  "price" => 1
  "pricesq" => 1
  "area" => 1
  "floor" => 1
  "height" => 1
]

按照你的写法,你的数组有一个元素,其值为 array:

array:1 [
  0 => array:9 [
    "lotid" => 1
    "lot" => 1
    "type" => 1
    "status" => 1
    "price" => 1
    "pricesq" => 1
    "area" => 1
    "floor" => 1
    "height" => 1
  ]
]

并且

$flatBuilder->update($arFields)
正在使用该元素(在本例中为 0)来查找相关列。

© www.soinside.com 2019 - 2024. All rights reserved.