📜  laravel 工厂关系一对多 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:28             🧑  作者: Mango

代码示例1
// parent factory 

    public function configure()
    {
        return $this->afterCreating(function (Category $category) {
            $posts = Post::factory(50)->make();
            $category->posts()->saveMany($posts);
        });
    }

// call in seeder
Category::factory(10)->create();