Laravel 10: Unexpected Duplicate Entries When Using Bulk Insert with Timestamps
I've been working on this all day and After trying multiple solutions online, I still can't figure this out. I'm currently working with an scenario with bulk inserting records into my Laravel 10 application. I'm using Eloquent to perform the insert, but despite trying to manage the timestamps, I'm getting duplicate entries in my database. Here's the code snippet I'm using for the bulk insert: ```php $data = [ ['name' => 'John Doe', 'email' => 'john@example.com'], ['name' => 'Jane Doe', 'email' => 'jane@example.com'], ['name' => 'John Doe', 'email' => 'john@example.com'], // Duplicate entry ]; DB::table('users')->insert($data); ``` The `users` table has the `email` column set as unique, and I expected to get a SQL behavior due to the duplicate entry, but instead, it seems to insert all rows, including duplicates, without any errors. I've tried adding `->unique()` in my query, but that didnโt seem to help either. Furthermore, I also verified that the timestamps are being correctly set by enabling the `timestamps` in the model as follows: ```php class User extends Model { public $timestamps = true; } ``` Interestingly, when I run a simple insert using a single entry, it respects the unique constraint as expected. However, with bulk inserts, itโs acting differently. Hereโs the behavior message I get if I try to check for duplicates after the insert: ``` SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'john@example.com' for key 'users_email_unique' ``` Thus, Iโm not sure if this is an scenario with Laravel's handling of bulk inserts or if there are any additional configurations I need to check. Any guidance on how to prevent these duplicates while still using bulk inserts would be greatly appreciated. My development environment is Windows. Am I missing something obvious? I'm on Debian using the latest version of Php. Could this be a known issue?