laravel数组使用不同的id更新多行



当我更新多个数组值时,我被卡住了,然后每次更新不同id中的相同值,比如我有三个字段,如电子邮件、alert_level和select。dropdown取决于alert_level-select选项,所以现在我想更新所有三个字段但在卡住的中

这是我的代码

if(!empty($requestData['edit_email']) && count($requestData['edit_email']) > 0){
foreach($requestData['edit_email'] as $i => $list){
$ids = array();
$editdata = array();
array_push($ids,$requestData['fid']);                    
$editrow['email']=$requestData['edit_email'][$i];
$editrow['phone'] = NULL;
switch($requestData['edit_email_alert_level'][$i]){
case 'client':
$editrow['alert_level'] = "client";
$editrow['client_id'] = (!empty($requestData['edit_locations'])) ? implode("," ,$requestData['edit_locations']) : NULL;
$editrow['salescenter_id'] = NULL;
$editrow['location_id'] = NULL; 
break;
case 'salescenter':
$editrow['alert_level'] = "salescenter";
$editrow['client_id'] = (!empty($requestData['edit_locations'])) ? implode("," ,$requestData['edit_locations']) : NULL;
$editrow['salescenter_id'] = NULL;
$editrow['location_id'] = NULL;
break;
case 'sclocation':
$editrow['alert_level'] = "sclocation";
$editrow['location_id'] = (!empty($requestData['edit_locations'])) ? implode("," ,$requestData['edit_locations']) : NULL; 
$editrow['client_id'] = NULL;
$editrow['salescenter_id'] = NULL;                            
break;
default:
break;
}                                  
FraudAlert::whereIn('id',$ids)->update($editrow);
}          
}

这是这种类型的错误SQLSTATE[42S22]:未找到列:1054"字段列表"中的未知列"0"(SQL:updatefraud_alertsset0=vandan@gmail.com,updated_at=2020-10-15 10:20:32其中id在(228((

这是$requestData 的dd

array:6 [▼
"_token" => "sTUoBilbfwZfp0x6tSdZhB4S5YQTO7l0xlip0QzA"
"clientId" => "102"
"fid" => array:2 [▼
0 => "228"
1 => "231"
]
"edit_email" => array:2 [▼
0 => "van@gmail.com"
1 => "demo@gmail.com"
]
"edit_email_alert_level" => array:2 [▼
0 => "sclocation"
1 => "client"
]
"edit_locations" => array:2 [▼
0 => "12"
1 => "3"
]

]

这是型号

protected $fillable = ['email', 'phone', 'alert_level', 'client_id', 
'salescenter_id', 'location_id', 'added_by', 'added_for_client', 'type'];

以下代码更新数据单个条目:-

if(!empty($requestData['edit_email']) && count($requestData['edit_email']) > 0){
foreach($requestData['edit_email'] as $i => $list){
$ids = $requestData['fid'][$i]; //current id
$editdata = array();
$editrow['email']=$requestData['edit_email'][$i];
$editrow['phone'] = NULL;
switch($requestData['edit_email_alert_level'][$i]){
case 'client':
$editrow['alert_level'] = "client";
$editrow['client_id'] = (!empty($requestData['edit_locations'])) ? implode("," ,$requestData['edit_locations']) : NULL;
$editrow['salescenter_id'] = NULL;
$editrow['location_id'] = NULL; 
break;
case 'salescenter':
$editrow['alert_level'] = "salescenter";
$editrow['client_id'] = NULL;
$editrow['salescenter_id'] = (!empty($requestData['edit_locations'])) ? implode("," ,$requestData['edit_locations']) : NULL;
$editrow['location_id'] = NULL;
break;
case 'sclocation':
$editrow['alert_level'] = "sclocation";
$editrow['location_id'] = (!empty($requestData['edit_locations'])) ? implode("," ,$requestData['edit_locations']) : NULL; 
$editrow['client_id'] = NULL;
$editrow['salescenter_id'] = NULL;                            
break;
default:
break;
}                                  
FraudAlert::where('id',$ids)->update($editrow);
}          
}

代码的问题是更新两个条目中的数据,但两行的数据相同。

最新更新