mercredi 27 janvier 2016

How can I maintain foreign keys when seeding database with Faker?

Below is my model factory.

$factory->define(App\Business::class, function (Faker\Generator $faker){
return [
'name' => $faker->bs,
'slug' => $faker->slug,
'address' => $faker->streetAddress,
'phone_no' => $faker->phoneNumber,
'mobile_no' => $faker->phoneNumber,
'email' => $faker->companyEmail,
'website' => $faker->domainName,
'latitude' => $faker->latitude,
'longitude' => $faker->longitude,
'location' => $faker->city,
'business_days_from' => $faker->dayOfWeek,
'business_days_to' => $faker->dayOfWeek,
'description' => $faker->text,
'user_id' => $faker->factory(App\User::class),
];

});

and This my database seeder class

class DatabaseSeeder extends Seeder
{
    public function run()
    {
        factory(App\Business::class, 300)->create();
    }
}

But when I execute php artisan db:seed ...it does not work..

What should be the workaround here..any help would be appreciated..



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1Sbazxs
via IFTTT

Aucun commentaire:

Enregistrer un commentaire