How can I solve this- SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value

  laravel, mysql, php

I have two tables with left join and want to update by area_id.
my update code is:

$area = Area::find($id);
            $city_id = DB::table('areas')->where("areas.id", $id)->select("areas.city_id")->join("locations", "areas.city_id", "=", "locations.id")
            ->get();

            if ($area) {
                $area->area_name = $request->input('areaName');
                $area->city_id = $city_id;
                $area->update();
                return response()->json([
                    'status' => 200,
                    'message' => $area['areaName'] . ' Updated successfully',
                ]);
            } else {
                return response()->json([
                    'status' => 400,
                    'message' => "Area Not found",
                ]);
            }

when I perform this I got an error which is below:

SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: '[{"city_id":1}]' for column `laravel_drywashbd`.`areas`.`city_id` at row 1 (SQL: update `areas` set `area_name` = Wari25, `city_id` = [{"city_id":1}] where `id` = 3)"

How can I solve this? Please help me.

Source: Laravel

Leave a Reply