【发布时间】:2016-05-17 04:20:54
【问题描述】:
我想通过 Laravel 上的数据库播种器使用 local、s3 和 rackspace 来播种数据库表。但是,如果我将这三个特定名称与 $faker->randomElement() 方法一起使用,它只会多次填充相同的名称,这就是我不需要的。如果可能,我还想使用s3 或rackspace 存储名称为不同的列设置不同的值。
$factory->define(App\Storage::class, function (\Faker\Generator $faker) {
return [
'storage' => $faker->randomElement(['s3', 'local', 'rackspace']),
's3-key' => null,
's3-secret' => null,
's3-region' => null,
's3-bucket' => null,
'rackspace-username' => null,
'rackspace-key' => null,
'rackspace-container' => null,
'status' => 'active'
];
})
实现这一目标的最佳方法是什么?
【问题讨论】:
-
试试这个,看看你是否得到相同的结果:$faker->randomElements(['s3', 'local', 'rackspace'],1)[0]
-
成功了。但是,不明白这是如何工作的。另外,当我想为
s3或rackspace设置s3-key或其他参数时,该怎么办。
标签: php laravel-5.2 faker