Skip to content

Instantly share code, notes, and snippets.

@mayanksdudakiya
Created May 31, 2023 13:28
Show Gist options
  • Select an option

  • Save mayanksdudakiya/ace57c84de69f1287b07bf14dec6687f to your computer and use it in GitHub Desktop.

Select an option

Save mayanksdudakiya/ace57c84de69f1287b07bf14dec6687f to your computer and use it in GitHub Desktop.
Laravel seed millions of data for testing
<?php
public function run()
{
$totalRecords = 50000; // Total number of records to generate
$batchSize = 200; // Number of records to insert per batch
DB::beginTransaction();
Website::factory()->count($totalRecords)->create()->chunk($batchSize, function ($websites) {
Website::insert($websites->toArray());
});
DB::commit();
DB::beginTransaction();
Theme::factory()->count($totalRecords)->create()->chunk($batchSize, function ($themes) {
Theme::insert($themes->toArray());
});
DB::commit();
DB::beginTransaction();
Plugin::factory()->count($totalRecords)->create()->chunk($batchSize, function ($plugins) {
Plugin::insert($plugins->toArray());
});
DB::commit();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment