Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I Have error "SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'field list'"

When i update table, laravel is broken
On another site same code work well


                        $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);
                        }

update dont work…
Where is my mistake?
Need help!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Since you’re already assigning array value to the $arFields, you don’t need to initialize it as empty array. Change your code to this (remove [] from $$arFields)

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

Result:

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

The way you wrote it, your array has one element, which has a value of array:

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

And $flatBuilder->update($arFields) is using that element (0 in this case), to find the relevant column.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading