You can do this to create five names.
Name::factory()->count(5)->create();
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
If I have a pre-defined array of values that I would like to insert into the database with one query (instead of looping over them and running n queries), is this possible?
For example:
$names = ['john', 'bob', 'martin', 'eric', 'joe', 'chris'];
foreach($names as $name) {
Name::factory()->create([
'name' => $name,
]);
}
Not too bad for 6 names but if I had defined 6000 names long array, then that would result in 6000 queries... yikes...
Please or to participate in this conversation.