jeudi 24 août 2017

Laravel : Bulk Insert Other and Ignore Error Exception Duplication

In mysql I have set unique key on column url and in Laravel controller I have create key value pairs of array to prepare bulk insert. I want to insert by ignore error duplication exception but insert for anothers. I have code as following:

controller.php

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()); 
 }

Thanks in advanced



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2w1YBQQ
via IFTTT

Aucun commentaire:

Enregistrer un commentaire