title: How to populate a nested category table with Faker in Laravel?
body: <p>I want to put the subcategory id into quote table but it seems too complicated! This is my try, obviously it ended up with a loop.</p>
  
  <p>Here is the seeder:</p>
  
  <pre><code>public function run()
  {
      factory(App\User::class, 50)-&gt;create()-&gt;each(function ($u) {
  
          $u-&gt;quotes()-&gt;save(
              factory(App\Quote::class)-&gt;make()
          );
  
      });
  }
  </code></pre>
  
  <p>And the quote factory:</p>
  
  <pre><code>return [
      'text' =&gt; $faker-&gt;paragraph,
      'author_id' =&gt; factory('App\Author')-&gt;create()-&gt;id,
      'category_id' =&gt; factory('App\Category')-&gt;create()-&gt;id
  ];
  </code></pre>
  
  <p>The category factory:</p>
  
  <pre><code>return [
      'name' =&gt; $faker-&gt;text,
      'parent_id' =&gt; factory('App\Category')-&gt;create()-&gt;id
  ];
  </code></pre>