如何为Laravel Mass updateOrCreate()准备PHP多维数组?

时间:2018-02-24 20:28:04

标签: php mysql laravel-eloquent mass-assignment laravel-5.6

我正在尝试大量插入Laravel(5.6)模型。有阵列准备问题;它返回

lluminate \ Database \ QueryException (42S22)
SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'field list' 
(SQL: insert into `_geolocation` (`0`, `1`, `2`, `3`, `4`) values 
(Manchester,+UK, Manchester,+UK, Manchester,+UK, Manchester,+UK, 
Manchester,+UK))

我正在生成这样的数组:

if($outputTo->status->message == "OK"){ // if
    for ($i = 0; $i < $outputTo->total_results; $i++) {
        //print_r($outputFrom->results[$i]->geometry->lat);
        $geodata_b [] =[
            $formattedAddrTo,
            $outputTo->results[$i]->formatted,
            $outputTo->results[$i]->geometry->lat,
            $outputTo->results[$i]->geometry->lng,
            ];
    }
}

这是我的数组输出;

    array:5 [▼
  0 => array:4 [▼
    0 => "Manchester,+UK"
    1 => "Manchester, Greater Manchester, England, United Kingdom"
    2 => 53.4791301
    3 => -2.2441009
  ]
  1 => array:4 [▼
    0 => "Manchester,+UK"
    1 => "Chapel Street Primary School, Chapel Street, Manchester M19 3GH, United Kingdom"
    2 => 53.443957
    3 => -2.1858478
  ]
  2 => array:4 [▼
    0 => "Manchester,+UK"
    1 => "The Manchester, Lytham Road, Bispham FY1 6AH, United Kingdom"
    2 => 53.8067298
    3 => -3.0549142
  ]
  3 => array:4 [▼
    0 => "Manchester,+UK"
    1 => "The Manchester, Bromsgrove Road, Bromsgrove B62 0HH, United Kingdom"
    2 => 52.4003403
    3 => -2.0539726
  ]
  4 => array:4 [▼
    0 => "Manchester,+UK"
    1 => "The Harlequin, Spitalfields, Sheffield S3 8GG, United Kingdom"
    2 => 53.3884864
    3 => -1.4663405
  ]
]

插入代码;

    $geolCache = \App\Geolocation::updateOrCreate([$geodata_b]);

我的模特;

protected $fillable = ['adrr','faddr','lat','lng'];

请有人帮我解决这个问题吗?

0 个答案:

没有答案