您好我正在尝试使用嵌套foreach
的查询结果在列中存储一些值:
if ($migrate_centers) {
$centersdt = $otf->getTable('centdt');
$centersdt = $centersdt->get();
$regions = $otf->getTable('ldt');
//$regions = $regions->get();
$regionsList = array();
$result = array();
try {
$regions = $regions->select('ldt.lname')->leftJoin('centdt', 'ldt.lid', '=', 'centdt.centregion')->groupBy('centdt.centregion')->get();
foreach($centersdt as $center) {
$center4 = new Center;
$center4->code = $center->centid;
$center4->phone = $center->centphone;
$center4->email = $center->centemail;
$center4->region_id = $center->centregion;
$center4->name = $Arabic->convert($center->centname);
foreach($regions as $reg) {
$center4->region = $Arabic->convert($reg->lname);
}
$center4->save();
}
} catch (Illuminate\Database\QueryException $e) {
return $e;
}
}
但我在所有行中只得到相同的值