I'm using Laravel and I'm trying to do a massive insert with :
try {
foreach ($users as $key => $user) {
DB::table('users')->insert(
[
'name' => $user->user_name,
'email' => $user->user_email,
]
);
}
} catch (\Exception $e) {
//something
}
So $users
is a big array and I do an insert for each element.
I have an unique constraint on my field email, so, if I have in my array multiple same emails, I get an error "Duplicate entry" and query just stop.
How can I continu insertion even if I have a duplicate entry ? Can I just ignore them ? (and get them for debug)
Thanks !