如何在唯一列中插入可能重复的行,如果插入了项目则返回?
尝试:
$id = DB::insert("INSERT IGNORE INTO question (id,text) values (10,'test')");
但$id
始终返回值= 1
也试过了:
$id = DB::table('question')->insertGetId(['id' => 10, 'text' => 'test'])->ignore();
但ignore()
无效!
答案 0 :(得分:0)
try {
DB::table('arv_groups')->insert([
'grouphash' => $grouphash,
'id_photo' => $id
]);
} catch(\Illuminate\Database\QueryException $e){
// I DON'T CARE IT'S DUPLICATE !!! THANK YOU VERY MUCH!
}