title: Seeding pivot table with Laravel 5.5 model factory - mb_strtolower() expects parameter 1 to be string, array given
body: <p>Given that I have the following tables:</p>
  
  <ul>
  <li>users</li>
  <li>questions</li>
  <li>tags</li>
  <li>question_tag <code>my pivot table with two fields: question_id &amp; tag_id</code></li>
  </ul>
  
  <p>and my <strong>App\Question</strong> model has the following relationships:</p>
  
  <pre><code>class Question extends Model
  {
      public function user()
      {
          return $this-&gt;belongsTo(User::class);
      }
  
      public function tags()
      {
          return $this-&gt;hasMany(Tag::class);
      }
  }
  </code></pre>
  
  <p>I've created the following factories:</p>
  
  <p><strong>database/factories/UserFactory.php</strong></p>
  
  <pre><code>$factory-&gt;define(App\User::class, function (Faker $faker) {
      static $password;
  
      return [
          'name' =&gt; $faker-&gt;name,
          'email' =&gt; $faker-&gt;unique()-&gt;safeEmail,
          'password' =&gt; $password ?: $password = bcrypt('123456')
      ];
  });
  </code></pre>
  
  <p><strong>database/factories/QuestionFactory.php</strong></p>
  
  <pre><code>$factory-&gt;define(App\Question::class, function (Faker $faker) {
      static $user_id;
  
      return [
          'user_id' =&gt; $user_id,
          'subject' =&gt; $faker-&gt;sentence(15),
          'body' =&gt; $faker-&gt;paragraph(10)
      ];
  });
  </code></pre>
  
  <p><strong>database/factories/TagFactory.php</strong></p>
  
  <pre><code>$factory-&gt;define(App\Tag::class, function (Faker $faker) {
      return [
          'name' =&gt; str_slug($faker-&gt;words(mt_rand(1, 2))),
          'description' =&gt; $faker-&gt;sentence()
      ];
  });
  </code></pre>
  
  <p>I tried to use it all together in my dummy data seeder like this:</p>
  
  <pre><code>class DummyDataSeeder extends Seeder
  {
      public function run()
      {
          // Seed dummy users
          factory(App\User::class, 10)-&gt;create()-&gt;each(function($user)
          {
              // With dummy questions
              $user-&gt;questions()-&gt;saveMany(factory(App\Question::class, 10)-&gt;make()-&gt;each(function($question)
              {
                  // With dummy tags
                  $question-&gt;tags()-&gt;sync(factory(App\Tag::class, 3)-&gt;make());
              }));
          });
      }
  }
  </code></pre>
  
  <p>When I run the seeder, I get the following error:</p>
  
  <blockquote>
    <p>[ErrorException]   mb_strtolower() expects parameter 1 to be string,
    array given</p>
  </blockquote>
  
  <p>Is this not possible to do in model factory? Do I need to use a different approach?</p>