Created
May 31, 2023 13:28
-
-
Save mayanksdudakiya/ace57c84de69f1287b07bf14dec6687f to your computer and use it in GitHub Desktop.
Laravel seed millions of data for testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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