I am inserting data if there is none(no problem with this part). But if there are same datas. I also want to update that and if data updated. Then I want it to keep old datas. Because I will use those.
Facing some trouble after inserting part. Updating data and keeping the old ones.
Here is my inserting and updating codes;
$oldData= allestates::where('link',json_encode($outlineUrl))->addSelect('id' , 'price')->limit(1)->get()->toArray();
if(!empty($oldData)) {
$oldData = (array)$oldData[0];
$oldData['updated_estate_id'] = $oldData['id'];
unset($oldData['id']);
\DB::table('updated_estates')->insertGetId($oldData);
allestates::where('link',json_encode($outlineUrl))->update(['price' => $changeForMyDB['price'] ]);
}else{
allestates::insertGetId($changeForMyDB);
$this->line('Data saved.');
}
I am having this error now:
SQLSTATE[HY000]: General error: 1364 Field 'link' doesn't have a default value (SQL: insert into updated_estates (price, updated_estate_id) values (1648万円(1戸)~3298万円(1戸), 1))
Also here is my database: the main table: https://i.stack.imgur.com/Kjncd.jpg
the updated table: https://i.stack.imgur.com/cxQJc.jpg