2017-08-24 65 views

回答

0
try{ 
    foreach ($js->RECORDS as $rec) { 
     $data = [ 
     'title'=>$rec->title, 
     'description'=>$rec->description, 
     'url'=>$rec->url 
     ]; 
    $status = Model::updateOrCreate(['url' => $rec->url], $data); 
    } 
}catch (\Exception $e){ 
    $req->session()->flash('alert-danger', $e->getMessage()); 
} 
+0

try{ $container = array(); foreach ($js->RECORDS as $rec) { $data = [ 'title'=>$rec->title, 'description'=>$rec->description, 'url'=>$rec->url ]; array_push($container, $data); } $status = Model::insert($container); }catch (\Exception $e){ $req->session()->flash('alert-danger', $e->getMessage()); } 

由於該解決方案將執行查詢一樣我的記錄有;但是,我想批量插入忽略重複的錯誤。 – Sovary