foreach ($updateOrInsert as $subordinate) {
if ($key = array_search($subordinate, $existingDowns))
{
// $update[] = ['id'=>$key,'up'=>$up,'down'=>$subordinate,'status'=>0];
$hierarchy = Hierarchy::find($key);
$hierarchy->status = 0;
$hierarchy->save();
}
else{
$insert[] = ['up'=>$up,'down'=>$subordinate];
}
}
这里$ key是hierarchies
表的ID。上面的代码仅更新了最后一个ID。我用谷歌搜索了这个问题,花了几个小时,但没有运气。有想法吗?