unique()->safeEmail; $emailParts = explode('@', $email); $emailParts[0] .= rand(1000, 9999); // Append a random 4-digit number $uniqueEmail = implode('@', $emailParts); $patientData[] = [ 'id' => $patientId, 'first_name' => $faker->firstName, 'last_name' => $faker->lastName, 'email' => $uniqueEmail, //'phone' => $faker->phoneNumber, 'password' => bcrypt("12345"), 'address' => $faker->address, 'city' => $faker->city, 'state' => $faker->state, 'zip_code' => $faker->postcode, 'lat' => $faker->latitude, 'long' => $faker->longitude, 'dob' => $faker->date($format = 'Y-m-d', $max = 'now'), 'recording_switch' => $faker->boolean, 'country' => $faker->country, 'phone_no' => $faker->phoneNumber, 'shipping_address' => $faker->address, 'shipping_city' => $faker->city, 'shipping_state' => $faker->state, 'shipping_country' => $faker->country, 'shipping_zipcode' => $faker->postcode, 'timezone' => 'UTC', 'gender' => $faker->randomElement(['male', 'female']), 'marital_status' => $faker->randomElement(['single', 'married']), 'height' => $faker->numberBetween(150, 200), 'weight' => $faker->numberBetween(50, 100), 'created_at' => now(), 'updated_at' => now(), ]; $patientRegActivityData[] = [ 'patient_id' => $patientId, 'activity' => 'patient_registered', 'created_at' => now(), 'updated_at' => now(), ]; $patientPlanData[] = [ 'patient_id' => $patientId, 'plan_id' => $plans->random()->id, 'created_at' => now(), 'updated_at' => now(), ]; } // Bulk insert data DB::table('patients')->insert($patientData); DB::table('patient_reg_activity')->insert($patientRegActivityData); DB::table('patient_plan')->insert($patientPlanData); $this->info("Inserted batch of $batchSize records. Total progress: " . ($j + $batchSize) . " / $totalRecords"); } $this->info('Data insertion completed successfully.'); } }