Laravel seeder only inserting one record; should insert 2500 - Stack Overflow

I have a Laravel seeder that is only inserting one record when I have a factory and the seeder should i

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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信