I have a Laravel seeder that is only inserting one record when I have a factory and the seeder should insert 2500 records.
Factory:
public function definition(): array
{
$timestamp = $this->getFakeTimestamp();
return [
'title' => $this->faker->sentence(),
'body' => $this->faker->paragraph(),
'more_inside' => $this->faker->paragraph(),
'subsite_id' => (new Subsite())->inRandomOrder()->first(),
'user_id' => (new User())->inRandomOrder()->first(),
'created_at' => $timestamp,
'published_at' => $timestamp,
'updated_at' => null,
'deleted_at' => null,
'is_published' => true,
'state' => PostStateEnum::Published->value,
];
}
Seeder:
final class FakePostSeeder extends Seeder
{
private const int NUMBER_OF_FAKE_POSTS = 2500;
public function run(): void
{
DB::connection()->disableQueryLog();
Post::factory(self::NUMBER_OF_FAKE_POSTS)->create();
}
}
One one row gets inserted, even if I replace the constant with an integer.
Passing the desired number with count doesn't work, either:
{
DB::connection()->disableQueryLog();
Post::factory()
->count(self::NUMBER_OF_FAKE_POSTS)
->create();
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744907079a4600321.html
评论列表(0条)