Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

AucT's avatar
Level 2

DB->insert ignore Batch records

I know there is

DB::table('users')->insert([ ['email' => '[email protected]', 'votes' => 0], ['email' => '[email protected]', 'votes' => 0] ]);

But I need insert ignore... Is there a way to batch insert ignore?

0 likes
6 replies
AucT's avatar
Level 2

@ZeyadMounir

As I'm insering data only for the user, I'm making precleaning - getting all the records (in my case with filter by user_id), then remove from array I'm going to batch insert that already in base.

If you are not using any filter and have lots of records try to find more about transactions. If I've got the docs you can start transaction make 1k insert ignore queries and the process transaction maybe it will go in a single request. But not sure if it works.

benjivm's avatar

What if I don't have a model for the table I'm trying to accomplish this with?

makopov's avatar

Has anyone had any luck with figuring this out? Has Laravel built-in support for it yet?

Please or to participate in this conversation.