title: Is there a way to limit Laravel factory seeding when calling one factory inside of another?
body: <p>I am currently following Laracasts and learning Laravel. I fully understand seeding and factories, but was wondering if there is a way to limit the amount of items a factory called within another factory can create? Maybe an arrow function? This is primarily because I don't want 30 users with my 30 posts, etc. I understand I could just call these separately in the seeder but that isn't the solution I am looking for, unless it is truly the only option.</p>
  <p>My Current PostFactory Code:</p>
  <pre><code>    class PostFactory extends Factory
  {
      /**
       * The name of the factory's corresponding model.
       *
       * @var string
       */
      protected $model = Post::class;
  
      /**
       * Define the model's default state.
       *
       * @return array
       */
      public function definition()
      {
          return [
              'user_id' =&gt; User::factory(),
              'category_id' =&gt; Category::factory(),
              'title' =&gt; $this-&gt;faker-&gt;sentence(),
              'slug' =&gt; $this-&gt;faker-&gt;slug(),
              'excerpt' =&gt; collect($this-&gt;faker-&gt;paragraphs(2))-&gt;map(fn($item) =&gt; &quot;&lt;p&gt;{$item}&lt;/p&gt;&quot;)-&gt;implode(''),
              'body' =&gt; collect($this-&gt;faker-&gt;paragraphs(6))-&gt;map(fn($item) =&gt; &quot;&lt;p&gt;{$item}&lt;/p&gt;&quot;)-&gt;implode(''),
          ];
      }
  }
  </code></pre>