如何将查询结果中的值存储到具有嵌套foreach的列中

时间:2016-04-22 17:09:24

标签: mysql laravel laravel-4 foreach

您好我正在尝试使用嵌套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;
    }
}

但我在所有行中只得到相同的值

0 个答案:

没有答案