我正在尝试为我的数据库添加一些特定的内容,以启动我的应用程序。我知道Faker以及如何使用它(我为我的用户做这件事)。现在我想用(很多)不是随机生成的记录来填充一个表,所以不是由Faker创建的。
例如我想要一个包含一些(比如说30个)俱乐部的表,这样我就可以生成一些无序的用户,他们是这30个俱乐部中$faker->randomElement
的成员。
还有其他方法可以把这个打30次吗?
$club = Club::create(array( 'name' => 'FC Barcelona', 'number' => '001', ));
在laravel(5.2)文档中找不到这个。只有骗子被解释了。
感谢
您可以创建一个包含俱乐部的数组并对其进行种子设置,在UsersDatabaseSeeder中,您可以创建任意数量的循环记录,并为每个记录分配随机俱乐部。
编辑
$clubs = [['prop1'=> 'val1',], ['prop1' => 'val2']];
DB::table('clubs')->insert($clubs);
Content::create(array(
'content_title' => 'Swiss Army Man',
'content_link' => 'www.Youtube.com',
'description' => 'This movie is .....',
'content_title' => 'Movie',
'image_path' => 'images/m1.jpg',
'year' => '2014-12-4'
));
Content::create(array(
'content_title' => 'Me Before You',
'content_link' => 'www.Youtube.com',
'description' => 'asdddddd',
'content_title' => 'Movie',
'image_path' => 'images/m2.jpg',
'year' => '2016-6-4'
));
,,, So You can create as many as u want ;)