Reputation: 5981
I want to seed a database table by using local, s3 and rackspace using database seeder on Laravel. However, if I use this three specific name with the $faker->randomElement()
method it just populate the same name multiple time and that's what I don't need. If possible, I also want to set the different value for the different column using s3
or rackspace
storage name.
$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'
];
})
What would be the best way to achieve this?
Upvotes: 1
Views: 1010
Reputation: 2978
There is a bug in the Faker/Provider/Baser.class, it is using this line of code inside the randomElement
Function which is duplicating the same random element over and over for the same instance due to the fact it is using static::
keyword
static::randomElements($array, 1);
I'll report about it, for the moment use this piece of code:
$faker->randomElements(['s3', 'local', 'rackspace'],1)[0]
Upvotes: 1