title: Laravel seed create wrong number of rows in DB
body: <p>I'm trying to create a seeder with relationships</p>
  
  <pre><code>public function run()
  {
      factory(Company::class, 10)-&gt;create()-&gt;each(function ($company){
          $company-&gt;buildings()-&gt;saveMany(factory(Building::class, 5)-&gt;create()-&gt;each(function ($building){
              $building-&gt;facilities()-&gt;saveMany(factory(App\Models\Facility::class,5)-&gt;make());
          }));
      });
  }
  </code></pre>
  
  <p>That code should creeate 10 companies and 5 buildings for each company and 5 facilities for each building. 
  companies 10
  buildings 50
  facilities 250</p>
  
  <p>but I get</p>
  
  <p>companies 300
  buildings 310
  facilties 250
  which doesn't make sense</p>
  
  <p>my factories:</p>
  
  <pre class="lang-php prettyprint-override"><code>$factory-&gt;define(Company::class, function (Faker $faker) {
      $name = $faker-&gt;lastName;
      $company = $name.' Company';
      return [
          'name' =&gt; $company,
          'shortName' =&gt; $name
      ];
  });
  </code></pre>
  
  <pre class="lang-php prettyprint-override"><code>$factory-&gt;define(Building::class, function (Faker $faker) {
      return [
          'name' =&gt; 'Hotel '.$faker-&gt;lastName,
          'company_id' =&gt; function () {
              return factory(App\Models\Company::class)-&gt;create()-&gt;id;
          }
      ];
  });
  </code></pre>
  
  <pre class="lang-php prettyprint-override"><code>$factory-&gt;define(Facility::class, function (Faker $faker) {
      $elements = array('lavabo','ducha');
  
      return [
          'name' =&gt; $faker-&gt;randomElement($elements).' '.$faker-&gt;numerify('Habitacion ###'),
          'building_id' =&gt; function () {
              return factory(App\Models\Building::class)-&gt;create()-&gt;id;
          }
      ];
  });
  </code></pre>
  
  <p>And the databaseSeeder.php</p>
  
  <pre><code>class DatabaseSeeder extends Seeder
  {
      /**
       * Seed the application's database.
       *
       * @return void
       */
      public function run()
      {
          $this-&gt;call(UserSeeder::class);
          $this-&gt;call(CompaniesSeeder::class);
      }
  }
  </code></pre>