How can I maintain foreign keys when seeding database with Faker?
<p>Below is my model factory.</p>

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

<p>});</p>

<p>and This my database seeder class</p>

<pre><code>class DatabaseSeeder extends Seeder
{
    public function run()
    {
        factory(App\Business::class, 300)-&gt;create();
    }
}
</code></pre>

<p>But when I execute <em>php artisan db:seed</em> ...it does not work..</p>

<p>What should be the workaround here..any help would be appreciated..</p>