📜  Laravel 8 Factory - 一对多(多态)关系 - PHP 代码示例

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

代码示例1
commentable();

        return [
            'body' => $this->faker->paragraph,
            'commentable_id' => $commentable::factory(),
            'commentable_type' => $commentable,
        ];
    }

    public function commentable()
    {
        return $this->faker->randomElement([
            Post::class,
            Video::class,
        ]);
    }
}